I have the working /.jenkins folder under a specific user in home on Linux. I want to start Jenkins with another user, but re-use the .jenkins folder of the other user. How can I do this? Jenkins offers some instructions but I don't get it :)
7 Answers
I think this can help you out.
Set an Environment Variable JENKINS_HOME
pointing to the .jenkins
folder and run the Jenkins command.
The shell should be like
export JENKINS_HOME=/usr/jhon/.jenkins
java -jar jenkins.war
The batch should be like
SET JENKINS_HOME=C:\users\jhon\.jenkins
java -jar jenkins.war
The
Powershell
should be like
[Environment]::SetEnvironmentVariable("JENKINS_HOME", "${PWD}\.jenkins")
java -jar jenkins.war
This will set your home directory to the current-working-directory + './jenkins'

- 21,375
- 7
- 100
- 81

- 4,238
- 6
- 36
- 54
-
Thanks, that worked. I needed to run a foreground slave server on a machine that already had Jenkins and so setting the ENV var in the script just before launch worked. – djangofan Sep 13 '13 at 22:57
-
if the jenkins war is running on a tomcat, kill the server and restart after exporting JENKINS_HOME. – Upen Jul 21 '15 at 04:01
-
This will cause an error: **Unable to create the home directory ‘JENKINS_HOME’. This is most likely a permission problem.** – IgorGanapolsky Jan 27 '17 at 19:58
-
Using the Java option -DJENKINS_HOME=... can be even more compact – Raúl Salinas-Monteagudo May 08 '19 at 06:51
Here are the options you have:
a) Assuming you're deploying Jenkins into Tomcat,you can do the following:
In your catalina.home/conf/localhost/jenkins.xml
<?xml version="1.0" encoding="UTF-8"?>
<Context docBase="/home/enomad/projects/jenkins/jenkins-master/war/target/jenkins" path="" reloadable="true">
<Environment name="JENKINS_HOME" value="/home/enomad/projects/jenkins-home"
type="java.lang.String" override="false"/>
</Context>
b) You can export the JENKINS_HOME=toWhateveryouwant as mentioned by Harsha in the previous post
c) You can extend your JAVA_OPTS params and add -DJENKINS_HOME=/path/to/jenkins_home/ as described here: Jenkins Mailing list
Good luck!

- 2,656
- 7
- 39
- 51

- 341
- 2
- 11
-
1Particularly helpful if you have to use tomcat service starters in Windows environments and need to have two Jenkins instances during migration. – Ben Steinert Jan 26 '17 at 09:32
I am using jenkins 1.639 as a war deployed on tomcat 7.0.67 . My JENKINS_HOME is set to /home/hims/jenkins
This is the entry of my setenv.sh file under /tomcat/bin directory
export CATALINA_OPTS="-DJENKINS_HOME=/home/hims/jenkins"
I hope this helps.

- 812
- 9
- 11
Jenkins was not taking JENKINS_HOME env variable i set for some weird reason.
The i added this line in tomcat start up script(/etc/init.d/tomcat).
$export JENKINS_HOME=/path/to/jenkins_home/
Now jenkins points to the new jenkins home :) This will be useful especially when you install jenkins on cloud. (on an Ec2 or eucalyptus intance)
Reference: https://wiki.jenkins-ci.org/display/JENKINS/Tomcat

- 2,031
- 3
- 34
- 44
Or you can modify the .bashrc so that it sets the environment variable everytime you start a console, that is, if you are using bash to start Jenkins.

- 164
- 12
In Tomcat 5 you can modify tomcat.conf and add the path:
export JAVA_OPTS="-DJENKINS_HOME=/home/jenkins"
Restart Jenkins.

- 11
- 1
Usually, you need to set the permissions for those files to be accessed by the new user.
See here: How to run jenkins as a different user -
especially the answers of Sagar and Peter Tran .
Cheers