43

How to change Jenkins default folder on Windows where Jenkins runs as Windows service. I want to change C:\Users\Coola\.jenkins folder to d:\Jenkins due to lack of space on C: partition (Every build takes ~10MB of free space). I don't want to reinstall Jenkins as Windows service. I just want to change folder of existing Jenkins instance. In case of lack of global solution I could focus only on relocating jobs folder.

Thanks in advance for your help.

Michał Kuliński
  • 1,928
  • 3
  • 27
  • 51

7 Answers7

41
  • Stop Jenkins service
  • Move C:\Users\Coola\.jenkins folder to d:\Jenkins
  • Using regedit, change HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Jenkins\ImagePath to "d:\Jenkins\jenkins.exe"
  • Start service
grams
  • 649
  • 8
  • 8
  • The answer helped. In addition, I had to wipe out the workspaces of all my jobs which use the tfs plugin to get the source code. This was failing with 'Unable to determine the workspace' error. – GarethOwen Nov 20 '12 at 10:37
  • 7
    I also had to add a new Inbound Rule to Windows Firewall, just duplicating the existing one for c:\Program Files (x86)\Jenkins\jre\bin\java.exe for the java.exe in the new folder – GarethOwen Nov 20 '12 at 13:29
  • 1
    The lower ranked answers that involve editting jenkins.xml allow a cleaner split between code and data. – Typhlosaurus Apr 22 '15 at 14:33
  • My version of Jenkins (installed from .msi) did not create a user based ".jenkins" folder. So, I had to go with a different answer - the convoluted one where a bunch of files had to be moved and the jenkins.xml had to be altered – Andrew Feb 21 '19 at 00:35
14

Apparently, grams' answer works but is not preferred. In Windows software and data/configuration files are supposed to reside in different places. This should be well known to Unix guys, it is basically like having a home directory. However, the wording with regard to JENKINS_HOME is broken anyways as setting an environment variable does not help despite what is being said in the help text.

I used the procedure that is described here: http://tech.nitoyon.com/en/blog/2014/02/25/jenkins-home-win/

Basically:

  1. Stop Jenkins service
  2. Edit entry <env name="JENKINS_HOME" value="%BASE%"/> in jenkins.xml in the Jenkins installation directory. This will be something like C:\Program Files (x86)\Jenkins. In your case value has to be set to d:\Jenkins
  3. Move Files from the installation directory to the new destination, d:\Jenkins, all except (some of them may not exist in a fresh installation)

    • jre folder
    • jenkins.err.log
    • jenkins.exe
    • jenkins.exe.config
    • jenkins.out.log
    • jenkins.war
    • jenkins.war.bak
    • jenkins.war.tmp
    • jenkins.wrapper.log
    • jenkins.xml

      1. Restart the service again.
kap
  • 1,456
  • 2
  • 19
  • 24
  • 2
    This worked for me. I also realized that I didn't need to move the "war" folder as it got regenerated in C:\Program Files (x86)\Jenkins. – Elijah Lofgren Aug 03 '17 at 18:22
5

When you read Administering Jenkins you can read all options how to modify the JENKINS_HOME environment variable.

On this website you can read how to configure you Tomcat container to override the JENKINS_HOME environment variable, they advise to create the file $CATALINA_BASE/conf/localhost/jenkins.xml, with the following content:

<Context docBase="../jenkins.war">
    <Environment name="JENKINS_HOME" type="java.lang.String" value="/data/jenkins" override="true"/>
</Context>
OblongZebra
  • 466
  • 5
  • 16
5

Here is the answer that worked for me: Jenkins: How to change JENKINS_HOME on Windows

Carlos
  • 361
  • 3
  • 7
  • 1
    ty @Carlos! that helped me too. The tip to go to the page; http://localhost:8080/systemInfo which shows all the variables was also extremely helpful. – AnneTheAgile Jan 09 '15 at 18:09
2

And in addition to grams answer, the most important part is creating an environment variable named JENKINS_HOME with value "D:\Jenkins". Without that, on starting Jenkins it would again create the .jenkins folder in your user home folder.

dunni
  • 43,386
  • 10
  • 104
  • 99
  • 1
    It may not be necessary. AFAIK it seems that the native windows installer does not create (or need) JENKINS_HOME environment variable. Check out [issue #JENKINS-13530](https://issues.jenkins-ci.org/browse/JENKINS-13530) But I guess it's safer to check JENKINS_HOME anyway. – grams Oct 03 '12 at 14:02
  • 1
    You don't need the Windows installer to install Jenkins as a service. You can also simply run the WAR and then select it from the menu. And in that case your right, it isn't necessary, since Jenkins creates a jenkins.xml file, which sets the current directory as JENKINS_HOME. – dunni Oct 03 '12 at 15:11
1

I was able to change the JENKINS_HOME variable following this http://tech.nitoyon.com/en/blog/2014/02/25/jenkins-home-win/

Setting JUST %JENKINS_HOME% as windows system wide environment variable didn't have any effect!

lukaz
  • 84
  • 4
0

We installed by dropping the .war into Tomcat, and could set home by just setting the environment variable JENKINS_HOME (with a service restart).

Ian Grainger
  • 5,148
  • 3
  • 46
  • 72