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.

- 5,179
- 10
- 35
- 56

- 387
- 1
- 5
- 12
-
It seems after change environment variable, you still need to access jenkins home (e.g `localhost:8080/jenkins`) once, to make it takes effects, it will show `wait a while, ...` – Eric Aug 07 '16 at 09:45
8 Answers
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.

- 2,532
- 4
- 26
- 30
-
1There is no **/etc/sysconfig** on some systems. It might be **/etc/init.d** – IgorGanapolsky Jan 27 '17 at 19:43
-
1
-
**With step 1 and 3, you can combined to one command:** `usermod -m -d /home/jenkins jenkins` – huytmb Apr 18 '19 at 02:44
-
If these steps does not work then, mv the directory /var/lib/jenkins to /var/lib/jenkins_bkp, then create the link of the directory in /var/lib/jenkins and restart jenkins – Abhishek Anvekar Sep 02 '22 at 08:02
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.

- 1,453
- 2
- 12
- 13
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:
-
Well but,what if its an anonymous User...In that case what should i look for..?? – user1728119 Nov 05 '12 at 05:03
-
Depending on how Jenkins is initiated (as a service or else), you could change it's user. Also please see my edited answer. – Gonen Nov 05 '12 at 09:09
I am using Ubuntu server and using Jenkins version (2.277.4 +). I was able to change the Jenkins home directory by:
- Changing the JENKINS_HOME value in
/etc/default/jenkins
to the desired folder name. - 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.

- 40,827
- 17
- 81
- 86
[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 :-
Stop Jenkins service - by killing the process
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/"
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.
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.

- 93
- 1
- 10
Follow steps:
sudo su
service jenkins stop
nano /etc/default/jenkins
- change
JENKINS_HOME
variable to whatever folder you want - save it
service jenkins start*

- 1,382
- 4
- 9
- 20

- 13
- 5
All previous answers may not work for you if you are using Jenkins version 2.332.1 or above and your Linux (Debian/RedHat) package installers using systemd to manage services.
To Change the Jenkins Home:
sudo systemctl stop jenkins
Run
sudo systemctl edit jenkins
( Will work Ubuntu and Centos both )And update the below lines: ( replace "/efs/jenkins-efs" with your new Jenkins home path"
[Service]
Environment="JENKINS_HOME=/efs/jenkins-efs"
WorkingDirectory=/efs/jenkins-efs
sudo systemctl start jenkins
Validate Jenkins home through Jenkins UI
Reference link : https://www.jenkins.io/doc/book/system-administration/systemd-services/ strong text

- 232
- 3
- 11