Can a Jenkins install use different paths for binaries and jobs, artifacts?

I'm installing Jenkins (on Windows) and would like the installation itself -- jenkins.war, jenkins.exe, plugins, to be on the system drive (C:), but the jobs and artifacts -- on D:

The documentation for JENKINS_HOME seems to suggest, that is not possible... Is that correct, or is there a separate variable -- or command-line switch -- I can use to tell the software to use separate paths for "code" and "data"?


Solution 1:

There is a documented option to separate the "code" (ie: jobs/jobname/config.xml) from the data" (ie; jobs/jobname/builds/...)

Use Jenkins Sytem Property jenkins.model.Jenkins.buildsDir.

jenkins.model.Jenkins.buildsDir

Default: ${ITEM_ROOTDIR}/builds

Description: The configuration of a given job is located under $JENKINS_HOME/jobs/[JOB_NAME]/config.xml and its builds are under $JENKINS_HOME/jobs/[JOB_NAME]/builds by default. This option allows you to store builds elsewhere, which can be useful with finer-grained backup policies, or to store the build data on a faster disk such as an SSD. The following placeholders are supported for this value:

${JENKINS_HOME}  – Resolves to the Jenkins home directory.
${ITEM_ROOTDIR} – The directory containing the job metadata within Jenkins home.
${ITEM_FULL_NAME} – The full name of the item, with file system unsafe characters replaced by others.
${ITEM_FULLNAME} – See above, but does not replace unsafe characters. This is a legacy option and should not be used.

For instance, if you would like to store builds outside of Jenkins home, you can use a value like the following: /some_other_root/builds/${ITEM_FULL_NAME} This used to be a UI setting, but was removed in 2.119 as it did not support migration of existing build records and could lead to build-related errors until restart.

Read additional details following the link about how to achieve for an existing configuration.

Usage

System properties are defined by passing -Dproperty=value to the java command line to start Jenkins. Make sure to pass all of these arguments before the -jar argument, otherwise they will be ignored. Example:

java -Dhudson.footerURL=http://example.org -jar jenkins.war

Caveat: Compatibility

We do NOT guarantee that system properties will remain unchanged and functional indefinitely. These switches are often experimental in nature, and subject to change without notice. If you find these useful, please file a ticket to promote it to an official feature.

ps: I don't know of a "ticket to promote it to an official feature", but I'd upvote any such request.

The above properties are counter-intuitively (ie: JENKINS_JAVA_OPTIONS):

System properties are defined by passing -Dproperty=value to the java command line to start Jenkins. Make sure to pass all of these arguments before the -jar jenkins.war argument, otherwise they will be ignored.

The basic sequence is:

$JAVA_HOME/bin/java $JENKINS_JAVA_OPTIONS -DJENKINS_HOME=$JENKINS_HOME -jar $JENKINS_WAR $PARAMS


I should also direct you to a related answer on Serverfault: Jenkins [networking] configuration parameters are to be used when installing or when running jenkins?. There are specific "code" related options to point to different directories. The following are "$PARAMS" to the war, so come after the -jar jenkins.war parameter.

Relevant summary listed below, but check your binary for options.

C:\apps\j2>java -jar jenkins-2.303.2.war  --help
Running from: C:\apps\j2\jenkins-2.303.2.war
webroot: $user.home/.jenkins
Jenkins Automation Server Engine 2.303.2

Options:
Usage: java -jar jenkins.war [--option=value] [--option=value]
   --webroot                = folder where the WAR file is expanded into. Default is ${JENKINS_HOME}/war
   --pluginroot             = folder where the plugin archives are expanded into. Default is ${JENKINS_HOME}/plugins
                              (NOTE: this option does not change the directory where the plugin archives are stored)
   --extractedFilesFolder   = folder where extracted files are to be located. Default is the temp folder
   --logfile                = redirect log messages to this file
   --javaHome               = Override the JAVA_HOME variable
   --toolsJar               = The location of tools.jar. Default is JAVA_HOME/lib/tools.jar
   --config                 = load configuration properties from here. Default is ./winstone.properties
   --commonLibFolder        = folder for additional jar files. Default is ./lib
   --extraLibFolder         = folder for additional jar files to add to Jetty classloader
   --usage / --help         = show this message