Saturday, September 21, 2024
Google search engine
HomeGuest BlogsHow to Change Jenkins Home Directory

How to Change Jenkins Home Directory

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 directoryHow 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 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
Linux var\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.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 buttonUnder 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 directoryThe 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 promptOpen 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 tabClick 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 sectionClick 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 variableSet 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 changesClick 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 fileEditing 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

RELATED ARTICLES

Most Popular

Recent Comments