31

To free up space on C:, I would like to move my Jenkins data files (specifically the \jobs directory) from the default installation directory C:\Program Files (x86)\Jenkins to F:\Jenkins\home. I think what I need to do is set the JENKINS_HOME environment variable to F:\Jenkins\home. But no matter what I try, the JENKINS_HOME environment variable is always set to the location of jenkins.exe.

Related:

Here is what I've tried so far:

  1. Moved jenkins data to F:\Jenkins\home
  2. Stop the running jenkins service
  3. Uninstall the jenkins service with jenkins.exe uninstall
  4. Uninstall jenkins
  5. Delete %HOMEPATH%\.jenkins directory
  6. Delete old jenkins install directory
  7. Download latest MSI installer v1.597
  8. Installed to C:\Program Files (x86)\Jenkins2 (renamed to ensure there are no stale values in the registry or config files)
  9. Set system-level environment variable JENKINS_HOME to F:\Jenkins\home
  10. Set user-level environment variable JENKINS_HOME to F:\Jenkins\home
  11. Modified jenkins.xml to use <env name="JENKINS_HOME" value="F:\Jenkins\home"/>
  12. Started the Jenkins service

At this point, when I look at the system configuration, JENKINS_HOME is set to C:\Program Files (x86)\Jenkins2. So it seems it must always be set to the location of jenkins.exe.

Maybe I've answered my own question. I'd like to have the program and data separate, if possible. Do I have to install jenkins to my F:\ drive? Or, is there a way to simply split off the jobs directory and leave everything else on C:?

Thanks!

EDIT : I did not have to move JENKINS_HOME, but instead was able to configure the workspace and builds directories, which moved all the heavy disk usage over to F:. The settings I chose were:

Workspace Root Directory = F:/Jenkins/workspace/${ITEM_FULLNAME} Build Record Root Directory = F:/Jenkins/jobs/${ITEM_FULL_NAME}/builds

I manually migrated these directories so they would not have to be recreated. During this process I did lose my build history, but I'm okay with that for now.

Community
  • 1
  • 1
cod3monk3y
  • 9,508
  • 6
  • 39
  • 54

8 Answers8

27

Pre Jenkins 2.121

JENKINS_HOME is where Jenkins is installed which is not what you want to change. After you start up Jenkins, go to:

  1. Manage Jenkins
  2. System Configuration
  3. Click the first "advanced" button

This gives you text fields where you can change the directory for the workspace and builds directories. Those are the two directories that use a good bit of disk space. Note that it will not move history. If you want to move the existing workspaces/etc, you'll need to manually copy them over.

Post 2.121 You have to set properties (not through the UI). The system property to use is jenkins.model.Jenkins.buildsDir.

https://jenkins.io/doc/upgrade-guide/2.121/#ui-option-for-custom-builds-and-workspace-directories-on-the-master-has-been-removed https://wiki.jenkins.io/display/JENKINS/Features+controlled+by+system+properties

Jeanne Boyarsky
  • 12,156
  • 2
  • 49
  • 59
17

Another possibility is to move the entire contents of $JENKINS_HOME.

It does not require editing configuration files, and it preserves the build history.

  1. Stop the running service: jenkins.exe stop

  2. Uninstall the service: jenkins.exe uninstall

  3. Copy C:\Jenkins\home to F:\Jenkins\home

  4. Rename C:\Jenkins to something else, keep it as backup.

  5. Go to F:\Jenkins\home

  6. Reinstall the service: jenkins.exe install

  7. Start Jenkins: jenkins.exe start

Enjoy the new disk space!

SpaceMonkey13
  • 188
  • 1
  • 7
15

For WINDOWS:

Copy all data from C:\Windows\System32\config\systemprofile\AppData\Local\Jenkins.jenkins to D:\Jenkins\home

Go to Jenkins installed folder C:\Program Files\Jenkins

  • Stop the running Jenkins service from the command line - jenkins.exe stop

  • Uninstall the Jenkins service from the command line - jenkins.exe uninstall

  • Update jenkins.xml as <env name="JENKINS_HOME" value="D:\JenkinsHome"/>

  • Install the Jenkins service from the command line- jenkins.exe install

  • Start the Jenkins service from the command line- jenkins.exe start

  • Login to Jenkins http://localhost:8080

  • Navigate to Manage Jenkins > Configure System

Verify Home directory must point to D:\JenkinsHome

Rajesh Singh
  • 159
  • 1
  • 4
7

For Jenkins 2.0, it was only necessary to add a system environment variable called "JENKINS_HOME" that points to the new location. The steps I used:

  1. Stop the container hosting Jenkins (e.g. Tomcat).
  2. Add a system environment variable called "JENKINS_HOME" that points to the new location.
  3. Restart the container hosting Jenkins.
Bernard
  • 7,908
  • 2
  • 36
  • 33
4

If you are using jenkins version older than 2.0 than you should do following:

1) open jenkins -> manage Jenkins -> Configure System. Check the path of your Home Directory. 2) Stop the jenkins service. 3) copy the jenkins home directory to other drive or location you want to move. 4) open jenkins.xml from program files and modify the value <env name="JENKINS_HOME" value="d:\Jenkins"/> Change the d:\Jenkins to your new path. 5) restart the Jenkins service. 6) test your job :)

user2125117
  • 749
  • 6
  • 5
4

first set the jenkins home path and then run /install jenkins.war

example :

set JENKINS_HOME=D:\
java -jar jenkins.war --httpPort=8091 -path=D:\<some-folder-name>\
Yasin Patel
  • 5,624
  • 8
  • 31
  • 53
4

Having the same problem and not wanting to change the whole %JENKINS_HOME% location, I came across the answer by adil ameen

Modify the config.xml file in %JENKINS_HOME% (typical under C:\Program Files (x86)\Jenkins). Change <workspaceDir> and <buildsDir> to your desired folder.

You can use the following placeholders: ${JENKINS_HOME}, ${ITEM_ROOTDIR}, ${ITEM_FULL_NAME}. As specified at Features controlled by system properties under jenkins.model.Jenkins.buildsDir

Mine looks like this:

  <workspaceDir>D:/jenkins/jobs/${ITEM_FULL_NAME}/workspace</workspaceDir>
  <buildsDir>D:/jenkins/jobs/${ITEM_FULL_NAME}/builds</buildsDir>

Reload the configuration through the Jenkins UI via Jenkins -> Manage Jenkins -> Reload configuration from disk

You can even keep your build history if you copy the old jobs to the new location.

gehbiszumeis
  • 3,525
  • 4
  • 24
  • 41
Tagman
  • 176
  • 2
  • 11
3

Stumbled upon this question because I was short on HDD on C:/ but had plenty on D:/.

The answer of Jeanne Boyarsky had exactly zero effect on my Jenkins. Although I changed the two variables, Jenkins still used the original workspace and jobs directories which consumed 1/3 of my C:/ drive.

A colleague pointed me to the dead easy solution of simply using Symbolic Links for the directories.

After shutting down Jenkins, open your CMD on the %JENKINS_HOME% directory and simply create two links for the big directories:

pushd %JENKINS_HOME%
:: save the old directories
ren workspace workspace.old
ren jobs jobs.old
:: now create the links
mklink /D /J workspace D:\jenkins\workspace
mklink /D /J jobs D:\jenkins\jobs
:: copy the original jobs to the new location
xcopy jobs.old\* jobs\ /sy

After this, restart your Jenkins. If everything works fine, you can safely delete the .old directories.

Community
  • 1
  • 1
eckes
  • 64,417
  • 29
  • 168
  • 201
  • 1
    This is a good way to do it; it gets the builds out of the default (and inappropriate) location in %Program Files (x86)%, while keeping the Jenkins blissfully unaware of the change. – Robert Calhoun Dec 16 '18 at 21:11