How to change home directory of Jenkins?

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.

  • Workflow that enforces code review and keeps the integration branch pristine (git, Stash, TeamCity)
  • How do I shallow clone a repo on a specific branch?
  • How to get SHA of commit for Xcode Bot “Run Script” Trigger? Updating status of tests on Github
  • How to build a pipeline of jobs in Jenkins?
  • Azure continuous build is failing with “Unable to initialize blade from definition”
  • Travis CI - android build failed. No connected devices error
  • Change the release process from SNAPSHOT to build number
  • Gulp won't work in Jenkins
  • Any tool to make git build every commit to a branch in a separate repository?
  • Building jenkins job only once, when tracking multiple branches?
  • How to simultaneously deploy Node.js web app on multiple servers with Jenkins?
  • Why does Jenkins/Maven give this error
  • 4 Solutions collect form web for “How to change home directory of Jenkins?”

    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

    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 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.

    Git Baby is a git and github fan, let's start git clone.