19

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 :)

user1340582
  • 19,151
  • 35
  • 115
  • 171

7 Answers7

40

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'

Aakash
  • 21,375
  • 7
  • 100
  • 81
Harshavardhan Konakanchi
  • 4,238
  • 6
  • 36
  • 54
12

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!

atlasloewenherz
  • 341
  • 2
  • 11
  • 1
    Particularly 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
2

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.

Himanshu Chauhan
  • 812
  • 9
  • 11
1

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

Venugopal Madathil
  • 2,031
  • 3
  • 34
  • 44
1

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.

xiurobert
  • 164
  • 12
1

In Tomcat 5 you can modify tomcat.conf and add the path:

export JAVA_OPTS="-DJENKINS_HOME=/home/jenkins"

Restart Jenkins.

Vympel
  • 11
  • 1
0

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

Community
  • 1
  • 1
Gonen
  • 4,005
  • 1
  • 31
  • 39