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.
- 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 System||Jenkins 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|
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.
3. Under System Configuration, click the Configure System button.
4. The first item in the list displays the location of 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.
6. Select the Advanced tab and click the Environment Variables button in the System Properties window.
7. Click the New button under the System variables section to add a new variable.
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.
9. Click OK in the Environment Variables window to save the changes to the system variables.
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:
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
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.