I have a Jenkins master slave configuration in a Centos machine. Previous all the Jenkins jobs were run as the root user in my slave node. 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.
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?
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.
If it's not an option you may use sudo
to run certain commands as a specific user. Passwords may be stored safely in Jenkins Credentials and injected as environmental variables in job. Then script may look like that ( sudopass
is injected secret):
echo $sudopass | sudo -S -u your_user your_command
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.