Steps to Changing Jenkins Home Directory – DZone


Home is

where the settings are.

What is the Jenkins Home Directory?

The Jenkins home directory contains all the details

of the Jenkins server configuration, details that are configured on the Manage Jenkins screen. These configuration details are stored in the form of a set of XML files. Much of the core configuration is stored in the config.xml file.

The Jenkins

home directory contains a subdirectory for each Jenkins build job managed by this instance of Jenkins. Each working directory, in turn, contains two subdirectories, builds, and workspace, along with a few other files. Contains the config.xml file for the build job, which contains, as expected, the configuration details for this build job.

There are also a few other files used internally by Jenkins that you wouldn’t normally touch, such as the nextbuildnumber file (which contains the number to be assigned to the next build in this build job), as well as symbolic links to the most recent successful build and the last stable one. A successful build is one that does not have any compilation errors. A stable build is a successful build that has passed the quality criteria you’ve set up, such as unit testing or code coverage.

Both build and workspace directories are important. The workspace directory is where Jenkins builds his project: it contains the source code that Jenkins removes, plus any files generated by the build itself. This workspace is reused for each successive build. There is only one workspace directory per project, and the disk space it requires tends to be relatively stable.

If the default home directory of the Jenkins

server was full or we want to run Jenkins jobs on a block volume or on a specific directory, we can do so by following these steps to change to the Jenkins home directory. Steps to change the Jenkins home directory

1. Click Manage Jenkins in the left corner of the Jenkins dashboard.

<img src="" alt=

“Manage Jenkins” />

Manage Jenkins

2. Select the System Information tab.

System InformationSystem


3. Scroll down to the Environment Variables section and you will see JENKINS_HOME

Environment VariablesEnvironment


4. Change the Jenkins login to the Jenkins server instance using Putty.

Using puttyUsing putty

5. Navigate to the root user using the following command.

sudo -i

6. Before changing anything in the Jenkins master we have to stop the Jenkins server.

Sudo Jenkins Service

Stop 7. Create a new directory where you want to move the Jenkins house. In this article, I create a new directory in /homepath.

mkdir /home/new_home

8. We need to change the ownership of a directory created using the chown command to change the user and group property of the created directory.

sudo chown jenkins:jenkins /home/new_home/

9. Copy the contents of the old Jenkins home directory, /var/lib/jenkins, to the new Jenkins home directory, /home/new_home/, using the following command.

sudo cp -prv /var/lib/jenkins /home/new_home/

10. Then, change the Jenkins user home page by using the following command.

sudo usermod -d /home/new_home/ Jenkins

11. Update the new Jenkins home directory path to /etc/default/jenkins.

sudo vi /etc/default/jenkins

12. Scroll down to the main location of Jenkins and update the new home directory path.

# default values for the Jenkins Automation server # extracted from the startup script; It makes things easier. NAME=jenkins # arguments to switch to java # Allow graphics etc. to work even when an X server is present JAVA_ARGS=”-Djava.awt.headless=true” #JAVA_ARGS=”-Xmx256m” # make jenkins listen on the IPv4 address #JAVA_ARGS=”” PIDFILE=/var/run/$NAME/$ # user and group to invoke as (default jenkins) JENKINS_USER=$NAME JENKINS_GROUP=$NAME # location of jenkins war file JENKINS_WAR=/usr/share/$NAME/$NAME.war # Jenkins house location JENKINS_HOME=/home/new_home

13. Start the Jenkins service by using the following command.

sudo service Jenkins home

14. Then we need to update the administrator password which can be found in a new Jenkins home directory.

cat /home/new_home/secrets/initialAdminPassword

15. Copy and paste the administrator password into the Administrator password field. Click the Continue button.

<img src="" alt=

“Unlock Jenkins” />

Unlock Jenkins

16. You will then be prompted to configure the first administrator user. Fill in all the required information and click the Save and Continue button.

17. Set the URL of your Jenkins instance. The URL will be generated automatically. Confirm the URL by clicking the Save and Finish button.

18. Once all the setup is done, you can see the “Jenkins is ready” screen. Click Start using Jenkins and you will be redirected to the Jenkins dashboard.

19. Click Manage Jenkins in the left corner of the Jenkins dashboard, then select System Information.

20. Scroll down to the Environment Variables section, you will see the new JENKINS_HOME.

<img src="" alt=

“New Jenkins home” />New


Create a freestyle project

Once the Jenkins home directory is changed, we can test previously created or new jobs. For the sake of this article, I created a new freestyle project.

1. Select New Item in the upper left corner of the dashboard.

new item

New item

2. Enter the project name in the Enter an item name field, select Freestyle Project, and click the OK button.

3. Enter a description (optional).

4. Go to the Build section and click the Add build step.

5. Select Run Shell as the build step.

6. Copy and paste the following command into a command field.


$HOME Execute ShellExecute


7. Click Save, you will be redirected to the job view page.

8. In the left pane, click the Build Now button to run your job.

9. We can check the build history run in the Build History by clicking on the build number, which is #1 in this case.

10. Click the build number and select Console Output. Here, you can see the Jenkins user homepage and Jenkins home directory. <img src="" alt=

“Jenkins Console Output” />Jenkins

Console Output

Further reading

Declarative Pipeline with Jenkins (RefCard)

Introduction to Jenkins: The Ultimate Guide

Contact US