How to Change Jenkins Home Directory

February 10, 2022

Introduction

Jenkins is an open-source automation server for software development. Jenkins keeps all the deployment logs, cloned repositories, build artifacts, and plugin configurations in the Jenkins Home directory.

In this tutorial, we will show you how to find the default Jenkins Home directory location and change it to a custom one.

How to change the Jenkins Home directory

Prerequisites

  • A copy of Jenkins installed and ready to use
  • Access to an account with sudo/administrator privileges.
  • Access to the terminal window or Command Prompt.
  • Access to a web browser.
  • Access to a text editor, such as Notepad or Nano.

Where is the Jenkins Home Directory Located?

The default location of the Jenkins Home directory depends on the operating system you are using:

Operating SystemJenkins Home Directory Location
Windows (as WAR file)C:\Users\Owner\.jenkins
Windows (as installation)C:\ProgramData\Jenkins\.jenkins or C:\Windows\System32\config\systemprofile\AppData\Local\Jenkins\.jenkins\secrets
Linuxvar\lib\jenkins

1. To check the default Jenkins Home directory location, use a web browser to open the Jenkins dashboard. In our case, we are browsing to http://localhost:8080/.

Note: By default, Jenkins uses the 8080 port. Read our article if you want to change the default Jenkins port.

2. Click the Manage Jenkins option on the left-hand side of the dashboard.

Location of the Manage Jenkins item on the Welcome to Jenkins page.

3. Under System Configuration, click the Configure System button.

Under System Configuration, click the Configure System button

4. The first item in the list displays the location of the current Jenkins Home directory.

The first item on the settings list displays the current Jenkins Home directory

Change Jenkins Home on Windows

As of Jenkins 2.0, changing the Home directory location on Windows requires you to add or edit the JENKINS_HOME environment variable. To do so:

1. Open the Command Prompt as an administrator.

2. Stop the Jenkins service by using:

net stop jenkins

3. Create a new Jenkins Home directory. For this example, we are using E:\jenkins_home\.jenkins.

4. Press Windows + R to open the Windows Run prompt.

5. Type in sysdm.cpl and click OK.

Open System Properties using the Windows Run prompt

6. Select the Advanced tab and click the Environment Variables button in the System Properties window.

Click the Environment Variables button under the Advanced tab

7. Click the New button under the System variables section to add a new variable.

Click the New button under the System variables section

8. Set JENKINS_HOME as the variable name and add the new Jenkins Home directory location as the variable value. Click OK to confirm the new variable.

Set the name and value for the new system variable

9. Click OK in the Environment Variables window to save the changes to the system variables.

Click OK in the Environment Variables window to save changes

10. Copy the contents of the default Jenkins Home directory to the new Home directory.

11. Use a text editor (such as Notepad) to open jenkins.xml in the Jenkins installation directory (C:\Program Files\Jenkins by default).

12. Change the line containing env name="JENKINS_HOME" value= to include the path to the new Jenkins Home directory. For instance, adding E:\jenkins_home\.jenkins as the new path:

<env name="JENKINS_HOME" value="E:\jenkins_home\.jenkins"/>

13. Save the changes to jenkins.xml and exit.

14. Restart the Jenkins service in the Command Prompt with:

net start jenkins

Change Jenkins Home on Linux

To change the Jenkins Home directory on Linux, create a new Home directory, copy the contents of the old Home directory to the new one and edit the Jenkins configuration file. In the example below, we are using Ubuntu 18.04.

1. In the terminal window, stop the Jenkins service with the following command:

sudo systemctl stop jenkins

2. Create a new Jenkins Home directory using the mkdir command. For this example, we are creating /home/jenkins_home:

sudo mkdir /home/jenkins_home

3. Change permissions for the new Home directory with:

sudo chown jenkins:jenkins /home/jenkins_home

4. Copy the contents from the old Jenkins Home directory to the new one:

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

5. Assign Jenkins as the user for the new Home directory with:

sudo usermod -d /home/jenkins_home jenkins

6. Open the Jenkins configuration file using a text editor (such as Nano):

sudo nano /etc/default/jenkins

Note: The default location for the Jenkins configuration file on Ubuntu and Debian is /etc/default/jenkins. If you are working with RedHat, CentOS, or Fedora, the Jenkins configuration file is located at /etc/sysconfig/jenkins.

7. Scroll down until you reach the JENKINS_HOME entry. Edit the line to include the path to the new Home directory. In this example, we are adding /home/jenkins_home as the new path:

JENKINS_HOME=/home/jenkins_home
Editing the Jenkins configuration file

8. Press Ctrl + X, then type Y and press Enter to save the changes.

9. Restart the Jenkins service to apply the new configuration:

sudo systemctl start jenkins

Conclusion

After reading this tutorial, you should be able to change the location of the Jenkins Home directory on Windows and Linux.

To learn more about managing and configuring Jenkins, take a look at our beginner's Jenkins tutorial.

Was this article helpful?
YesNo
Aleksandar Kovačević
With a background in both design and writing, Aleksandar Kovacevic aims to bring a fresh perspective to writing for IT, making complicated concepts easy to understand and approach.
Next you should read
Jenkins Logs - Viewing and Customizing
December 30, 2021

Jenkins is an open-source automation server for code development. Jenkins logs offer a wealth of information about your projects and the Jenkins app itself.
Read more
How to Change Port for Jenkins
December 29, 2021

Jenkins uses port 8080 by default, but it also lets users set a custom port. This tutorial shows you how to change the default Jenkins port in Windows, Linux, and macOS.
Read more
Jenkins Environment Variables: Ultimate Guide
December 23, 2021

Jenkins is an open-source automation server used for automating code development. In this tutorial, we show you how to use environment variables in Jenkins to make automation even easier.
Read more
How to Restart Jenkins Manually
December 16, 2021

Jenkins offers a way for developers to automate building, testing, and deploying their applications. This tutorial show you how to restart Jenkins manually.
Read more