以 root 用户身份在 jenkins 中运行 shell 命令? [英] Run shell command in jenkins as root user?

查看:60
本文介绍了以 root 用户身份在 jenkins 中运行 shell 命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近开始使用 Jenkins 进行集成.一切都很好,直到我在没有 shell 命令的情况下在主节点上运行作业,但我必须在主节点和包含 shell 命令的从节点上运行作业.我无法以 root 用户身份运行这些 shell 命令.我试过了

I have recently started using Jenkins for integration. All was well until I was running jobs on master node without shell command but I have to run jobs on master as well as slave node which contains shell commands to. I am not able to run those shell commands as root user. I have tried

  1. 使用 SSH 密钥.
  2. 在 shell 命令中设置用户名.
  3. 使用sudo.

我每次使用上述任何一种方法时都会收到 permission denied 错误.

I am getting permission denied error every time I use any of the above methods.

推荐答案

您需要修改 jenkins 用户的权限,以便您可以运行 shell 命令.您可以将 jenkins 作为服务安装(下载 rpm 包),您可能需要更改端口,因为默认情况下它在 8080 端口上运行 http,在 8009 端口上运行 AJP.

You need to modify the permission for jenkins user so that you can run the shell commands. You can install the jenkins as as service (download the rpm package), You might need to change the ports because by default it runs http on 8080 and AJP on 8009 port.



以下流程适用于CentOS
1.打开这个脚本(使用VIM或其他编辑器):



Following process is for CentOS
1. Open up the this script (using VIM or other editor):

vim /etc/sysconfig/jenkins

2.找到这个 $JENKINS_USER 并更改为root":

2. Find this $JENKINS_USER and change to "root":

$JENKINS_USER="root"

3.然后更改Jenkins home、webroot和logs的所有权:

3. Then change the ownership of Jenkins home, webroot and logs:

chown -R root:root /var/lib/jenkins
chown -R root:root /var/cache/jenkins
chown -R root:root /var/log/jenkins

4) 重启 Jenkins 并检查用户是否已更改:

4) Restart Jenkins and check the user has been changed:

service jenkins restart
ps -ef | grep jenkins

这篇关于以 root 用户身份在 jenkins 中运行 shell 命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆