简体   繁体   English

如何在 Linux 的从节点中运行 Jenkins 作业时指定用户

[英]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.

相关问题 如何为Windows从属服务器指定Jenkins(Linux)的默认用户 - How to specify default user for Jenkins (linux) to Windows slave 詹金斯如何查找给定的奴隶是否正在运行作业 - Jenkins How to find if a given slave is running a Job 在X奴隶Y上运行时,启动对X的Jenkins作业 - Initiate Jenkins job on salve X while it’s running on slave Y jenkins作业构建不在从节点中 - jenkins job build not in slave node 如何在Jenkins CI从节点上运行robotframework作业 - How to run a robotframework job on a Jenkins CI slave node 在我的 CiCD 管道中,从从 Jenkins 节点(Windows 节点)到主 Jenkins 节点(Linux 节点)的通信在作业执行过程中中断 - In my CiCD pipeline , communication from Slave Jenkins node(Windows node) to Master Jenkins node(Linux node) breaks in middle of job execution Jenkins - 在 master 和 slave 中运行单个作业 - Jenkins - Running a single job in master as well as slave 在运行 jenkins 作业之前检查从站是否存在 - Check for slave existence before running a jenkins job 当作业中存在节点选择插件时,如何将jenkins作业路由到任何可用的节点/从属节点 - How to route a jenkins job to any available Node/slave when node selection plugin too present in job 在Windows Jenkins从属节点上运行Protractor时出现问题 - Problems running Protractor on a Windows Jenkins Slave Node
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM