Question

Simple question: How to change the jenkins home directory location? By default it points to /var/lib/jenkins whereas I want it to point to /home/jenkins. I have changed my $JENKINS_HOME to /home/jenkins but it doesn't help me.

Was it helpful?

Solution

Jenkins usually runs with its own user,
so changing the home-dir of that user should do the job.

If not sure, simply run a test-job with a shell-command like 'id' or 'whoami' or 'env' to find the user that Jenkins uses.

Also, note that a message of "Started by user anonymous" does not mean that Jenkins started as an anonymous user -
please see this related answers by Sagar and Peter Tran:

how to run jenkins as a different user

OTHER TIPS

For me on Jenkins 2.7.2 on RHEL 7.2 after already starting jenkins and configuring a build, I needed to:

1) Change the jenkins user's home directory

sudo su -
service jenkins stop
vi /etc/passwd
#  change the /var/lib/jenkins to /home/jenkins or whatever 

2) Change the setting in the start script to also find it

vi /etc/sysconfig/jenkins
#   change the JENKINS_HOME to /home/jenkins or what ever

3) Copy all the data to the new location (eg: /home/jenkins)

cd /home
cp -Rf /var/lib/jenkins .
chown -R jenkins:jenkins *

4) Start it back up

service jenkins start

And that seems to have done it for me.

To change the Jenkins home directory you just need to setup the "JENKINS_HOME" environment variable to point to the new location. You can also set the JENKINS_HOME as a system property or a JNDI environment entry as explained in the documentation.

Jenkins Documentation

I am using Ubuntu server and using Jenkins version (2.277.4 +). I was able to change the Jenkins home directory by:

  1. Changing the JENKINS_HOME value in /etc/default/jenkins to the desired folder name.
  2. Update permission on the target folder so that jenkins user has read,write,execute permissions on the folder.

I tried setting the PATH thing but it doesn't seem to work as it probably has to be under Jenkins user which does not have a real unix user account. I found the variable also accessible in /etc/sysconfig/jenkins which did the trick when I restarted Jenkins.

[A] Find your current jenkins home folder, if you are not aware where it is ?
Jenkins -> Manage Jenkins -> Configure System -> Check label 'Home directory'

[B] To move current Jenkins home folder to a new directory. Follow below steps :-

  1. Stop Jenkins service - by killing the process

  2. Follow one of below approach to set new home folder for JENKINS.

    a) By default Jenkins home directory is set to ~/.jenkins
    b) "JENKINS_HOME" environment variable setup in operating system.
    c) "JENKINS_HOME" entry in JNDI environment.
    d) "JENKINS_HOME" system property to the servlet container.
            Tomcat context descriptor of the servlet, you can set below field in apache-tomcat-8.5.28/conf/context.xml :
            <Context ...>
              <Environment name="JENKINS_HOME" value="/path/to/jenkins_home/" type="java.lang.String"/>
            </Context>
    
    e)  If jenkins.war file is deployed in a tomcat server , then even appending below content in bin/catalina.sh will setup JENKINS_HOME.
                CATALINA_OPTS="-DJENKINS_HOME=/path_to/jenkins_home/"
    
  3. Manually copy Jenkins home folder content from old to new home folder. (In windows , ctrl + c / v . In Unix , use cp command) . Instead of moving, copy step is advised to keep one backup. Later we can delete old workspace.

  4. Now start Jenkins, then It will pick the new home directory from the path mentioned in JENKINS_HOME variable.

    Note: - Just by setting above variable "JENKINS_HOME" to a different path will not copy the files from current Jenkins home path to new one automatically. This copy step - you have to do it yourself, Manually.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top