[英]How to specify the user while running a Jenkins job in a slave node in Linux
I have a Jenkins master slave configuration in a Centos machine.我在 Centos 机器上有一个 Jenkins 主从配置。 Previous all the Jenkins jobs were run as the root user in my slave node.
以前,所有 Jenkins 作业都在我的从节点中以 root 用户身份运行。 Now I see that the jobs are run as another user.
现在我看到作业以另一个用户身份运行。
I was trying to figure out the configuration where I can specify the user for a job in the Jenkins slave configuration or in job level.我试图找出可以在 Jenkins slave 配置或作业级别中为作业指定用户的配置。
My job includes code checkouts and folder creations.我的工作包括代码签出和文件夹创建。 Since the job is supposed to be executed as different user, I am facing a lot of permission issues.
由于该作业应该以不同的用户身份执行,因此我面临很多权限问题。 Is there any way to specify the linux user for a jenkins job or node?
有没有办法为 jenkins 作业或节点指定 linux 用户?
The easiest way is to configure whole slave to work as specific user (in node configuration: Nodes -> [your node] -> Configure -> Launch method -> Credentials ) and grant all needed permissions to that user.最简单的方法是将整个从站配置为特定用户(在节点配置中: Nodes -> [your node] -> Configure -> Launch method -> Credentials )并将所有需要的权限授予该用户。
If it's not an option you may use sudo
to run certain commands as a specific user.如果这不是一个选项,您可以使用
sudo
以特定用户身份运行某些命令。 Passwords may be stored safely in Jenkins Credentials and injected as environmental variables in job.密码可以安全地存储在 Jenkins Credentials 中,并在作业中作为环境变量注入。 Then script may look like that (
sudopass
is injected secret):然后脚本可能看起来像这样(
sudopass
被注入秘密):
echo $sudopass | sudo -S -u your_user your_command
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.