Change JENKINS_HOME on Red Hat Linux?

I used this procedure to install Jenkins:

https://wiki.jenkins-ci.org/display/JENKINS/Installing+Jenkins+on+RedHat+distributions

  • Passing arguments to Maven release build
  • Sonarqube scan from Jenkins : ClassNotFoundException: org.eclipse.jgit.api.Git
  • Jenkins set github commit status not working
  • Jenkins pipeline stages - passing whole file
  • Jenkins Maven Build 137 Error
  • Deployment to Azure from Jenkins not working because of “A network-related or instance-specific error occurred” (Error 26)
  • After it was up and running I discovered the /var/lib/jenkins partition on my server is very small. I want to move it, but I do not want to change the user that it runs under. I am new to Linux and I’m stumped. How do I move it for example to my Home/Public folder? The “Jenkins” user doesn’t seem to have a Home folder. Its running as a daemon on startup, so I have no idea where to configure those settings.
    Can I create a Home folder for the Jenkins user? How?

    I read this article:

    https://wiki.jenkins-ci.org/display/JENKINS/Administering+Jenkins

    but do not understand HOW to “set the new Jenkins home”. I have used the export command, and restarted the service, but the old path still shows up in the Manage Jenkins screens.

    I’ve read the 2-3 similar questions on stackoverflow also, but there’s always a big missing piece for me. Where to find that file where I change the path permanently?

  • Jenkins guide needed for build, deploy, provision and rollback, keeping 5 releases
  • Running a Post Build script when a Jenkins job is aborted
  • Jenkins Groovy: What triggered the build
  • Jenkins not working anymore: SSH executable not found
  • Jenkins - Get code from BitBucket with SSH
  • Is there any way to cleanup Jenkins workspace?
  • 5 Solutions collect form web for “Change JENKINS_HOME on Red Hat Linux?”

    Here’s an easy way to solve your problem. First, move the Jenkins directory from /var/lib/jenkins to /home/jenkins. Then create a symlink at /var/lib/jenkins pointing to /home/jenkins. And of course, stop the Jenkins service before doing that.

    sudo service jenkins stop
    sudo mv /var/lib/jenkins /home
    sudo ln -s /home/jenkins /var/lib/jenkins
    sudo service jenkins start
    

    I managed to change the home location for Jenkins by modifying content of /etc/sysconfig/jenkins file as follows:

    JENKINS_HOME="/home/jenkins"
    

    Okay, I reread your question a little bit more closely, lets see if we can figure this out. I am going to list some info that you may or may not know.

    1. The jenkins installation and jenkins home are not the same thing. One is where the war file and other parts that jenkins needs to run live. jenkins_home is where your data is stored. By default, jenkins_home lives in ~/.jenkins. When you start jenkins, it looks for an environment variable to tell it where to find those files.

    2. Jenkins runs as a seperate user, which, by default, is jenkins. This way it doesn’t get in the way of you. The jenkins user will not have access to YOUR home directory, so that would be a poor solution. Ideally, it would have its own home directory, /home/jenkins. Your home directory could then be /home/jenkins/.jenkins. You say that folder doesn’t exist- if you don’t have access to it to create it yourself, that is perfectly fine, you can specify ANY folder. However, the jenkins user must have ownership of that folder to read and write to it.

    3. It looks like Jenkins on redhat will be running with tomcat by default. The documentation for how to set environment variables for tomcat is https://wiki.jenkins-ci.org/display/JENKINS/Tomcat

    4. This all gets set up with a script.https://wiki.jenkins-ci.org/display/JENKINS/JenkinsLinuxStartupScript seems to be the one that is used for this purpose. Even if you don’t know anything about shell scripting, this isn’t too hard… lines with a # are comments. The first line

      JENKINS_USER=jenkins

    sets the name of the user account jenkins will be using. Look down a littlle further, and you’ll see the line

    export JENKINS_BASEDIR=/home/jenkins
    
    export CATALINA_OPTS="-DJENKINS_HOME=$JENKINS_BASEDIR/jenkins-home -Xmx512m -Djava.awt.headless=true"
    

    This lets you set a directory to where jenkins should live, and then sets the jenkins_home directory to that /jenkins-home.

    For your application, you may want to do something like this

    export CATALINA_OPTS="-DJENKINS_HOME=/var/jenkinsmount/home -Xmx512m -Djava.awt.headless=true"
    

    That would then store all of your build data (which is the part that grows!) at /var/jenkinsmount/home … while leaving the rest of your files in their current location.

    I haven’t used it on redhat, but hopefully I explained enough for you to actually understand what is going on so that you can get it going!

    Other INFO:

    https://wiki.jenkins-ci.org/display/JENKINS/Installing+Jenkins+as+a+Unix+daemon

    I have faced the same issue and question.
    Connecting some dots I could fix my Jenkins after I moved Jenkins to a new location due to the same issue -space in disk under /var/lib/jenkins.

    Here is the procedures that I had to follow to get it working taking in consideration that I am pointing Jenkins to a non-default port. (I have applied this process into 2 servers)

    First, move the Jenkins directory from /var/lib/jenkins to /opt/jenkins

    sudo service jenkins stop
    sudo mv /var/lib/jenkins /opt/
    

    Now you can change your workspace and build directory to any other location on your machine.
    Jenkins provides 3 predefined variables that can be used to specify the new location:

    JENKINS_HOME — Jenkins home directory

    ITEM_ROOTDIR — Root directory of a job for which the workspace is allocated

    ITEM_FULLNAME — ‘/’-separated job name, like “foo/bar”

    sudo su jenkins (access as Jenkins user)
    JENKINS_HOME=/opt/jenkins
    ITEM_ROOTDIR=/opt/jenkins
    ITEM_FULLNAME=/opt/jenkins
    exit (exit Jenkins user)
    

    Now, edit the jenkins config

    /opt/jenkins$ sudo nano /etc/default/jenkins
    

    Modify the following line

    #jenkins home location
    #JENKINS_HOME=/var/lib/$NAME (here is the default)
    JENKINS_HOME=/opt/jenkins (that is our new location)
    

    change the home directory of a user

    sudo usermod -d /opt/jenkins/ jenkins
    sudo service jenkins start
    

    Richard Chen’s location is where I found the jenkins file on my CentOS 6.6 system.

    1. sudo service jenkins stop
    2. mv /var/lib/jenkins /home/mylocation/
    3. (made sure the new location had correct ownership and group– Jenkins)
    4. modified the content of the file /etc/sysconfig/jenkins as follows:

      JENKINS_HOME=”/home/mylocation”

    5. sudo service jenkins start
    Git Baby is a git and github fan, let's start git clone.