Friday, May 25, 2018

CentOS7.2 - How To Run Jenkins Under Different User

After successfully install Jenkins, you can set which user you want Jenkins service to run under.

$ sudo wget -O /etc/yum.repos.d/jenkins.repo
$ sudo rpm --import
$ yum install jenkins

The correct way to do this is to update the "/etc/sysconfig/jenkins" file, instead of change the JENKINS_USER variable in "/etc/init.d/jenkins".

To change the jenkins user, open the /etc/sysconfig/jenkins (in debian this file is created in /etc/default) and change the JENKINS_USER to whatever you want. You have to make sure that user exists in the system (you can check the user in the /etc/passwd file ).
Then change the ownership of the Jenkins home, Jenkins webroot and logs.
$ chown -R tony:tony /var/lib/jenkins
$ chown -R tony:tony /var/cache/jenkins
$ chown -R tony:tony /var/log/jenkins

Then restarted the Jenkins jenkins and check the user has changed using a ps command
$ /etc/init.d/jenkins restart
$ ps -ef | grep jenkins

No comments: