How to set Jenkins installation file location? - jenkins

I want to set Jenkins file location to E:\Programs\Jenkins kind of location
I'm using the command java -jar jenkins.war
How do i specify the file location with that commad

I think you mean jenkins home. Just specify JENKINS_HOME environment variable before launching jenkins. If you are using Windows go to user accounts configuration and change your environment variables. Add variable JENKINS_HOME with value E:\Programs\Jenkins.

Related

How do I change user.timezone in system properties when jenkins is run as war?

If jenkins is installed as a package manager, user.timezone can be modified by editing the jenkins file in the /etc/default/ path.
However, when running jenkins as war, there is no file in the path, so it cannot be set.
Is there a file or method to modify the system properties of jenkins when it is run as war?
You can pass the timezone as the system property user.timezone when starting the war file like java -Duser.timezone=America/Chicago -jar jenkins.war. You can verify that the timezone has been set correctly by going to the jenkins_host/systemInfo page

Jenkins envInject Plugin not picking PATH

I have my Jenkins configured to Inject environment variables to the build process and set the Properties File Path to G:\Jenkins\env.properties
Inside my env.properties
VISUALSTUDIOVERSION=12.0
PATH=$PATH
When I run my job, the PATH is not reflecting my system path instead its just showing $PATH only. How can I edit my env.properties file to pick up system PATH?
THe output of Env variables after build is
VISUALSTUDIOVERSION=12.0
PATH=$PATH
But I am expecting to see it as
VISUALSTUDIOVERSION=12.0
PATH=C:\Program Files (x86)\Perl\site\bin;C:\Program Files (x86)\Perl\bin;
Environment variables in Java are case-sensitive. Try Path instead of PATH.

How to change workspace and build record Root Directory on Jenkins?

I would like Jenkins' data to be written to drive "E:" since this is the large drive on the server. Jenkins itself is installed on "C:".
How do I do that?
The default configuration that I saw is:
Workspace Root Directory: ${ITEM_ROOTDIR}/workspace
Build Record Root Directory: ${ITEM_ROOTDIR}/builds
Will the following changes help me achieve what I need?
Workspace Root Directory: E:/Jenkins/workspace
Build Record Root Directory: E:/Jenkins/builds/${ITEM_FULL_NAME}
In addition, what does "${ITEM_FULL_NAME}" mean?
I figured it out.
In order to save your Jenkins data on other drive you'll need to do the following:
Workspace Root Directory: E:\Jenkins\${ITEM_FULL_NAME}\workspace
Build Record Root Directory: E:\Jenkins\${ITEM_FULL_NAME}\builds
You can modify the path on the config.xml file in the default directory
<projectNamingStrategy class="jenkins.model.ProjectNamingStrategy$DefaultProjectNamingStrategy"/>
<workspaceDir>D:/Workspace/${ITEM_FULL_NAME}</workspaceDir>
<buildsDir>D:/Logs/${ITEM_ROOTDIR}/Build</buildsDir>
EDIT: Per other comments, the "Advanced..." button appears to have been removed in more recent versions of Jenkins. If your version doesn't have it, see knorx's answer.
I had the same problem, and even after finding this old pull request I still had trouble finding where to specify the Workspace Root Directory or Build Record Root Directory at the system level, versus specifying a custom workspace for each job.
To set these:
Navigate to Jenkins -> Manage Jenkins -> Configure System
Right at the top, under Home directory, click the Advanced... button:
Now the fields for Workspace Root Directory and Build Record Root Directory appear:
The information that appears if you click the help bubbles to the left of each option is very instructive. In particular (from the Workspace Root Directory help):
This value may include the following variables:
${JENKINS_HOME} — Absolute path of the Jenkins home directory
${ITEM_ROOTDIR} — Absolute path of the directory where Jenkins stores the configuration and related metadata for a given job
${ITEM_FULL_NAME} — The full name of a given job, which may be slash-separated, e.g. foo/bar for the job bar in folder foo
The value should normally include ${ITEM_ROOTDIR} or ${ITEM_FULL_NAME}, otherwise different jobs will end up sharing the same workspace.
The variables you need are explained here in the jenkins wiki: https://wiki.jenkins.io/display/JENKINS/Features+controlled+by+system+properties
The default variable ITEM_ROOTDIR points to a directory inside the jenkins installation. As you already found out you need:
Workspace Root Directory:
E:/myJenkinsRootFolderOnE/${ITEM_FULL_NAME}/workspace
Build Record Root Directory: E:/myJenkinsRootFolderOnE/${ITEM_FULL_NAME}/builds
You need to achieve this through config.xml nowerdays. Citing from the wiki page linked above:
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.
I would suggest editing the /etc/default/jenkins
vi /etc/default/jenkins
And changing the $JENKINS_HOME variable (around line 23) to
JENKINS_HOME=/home/jenkins
Then restart the Jenkins with usual
/etc/init.d/jenkins start
Cheers!
You can also edit the config.xml file in your JENKINS_HOME directory.
Use c32hedge's response as a reference and set the workspace location to whatever you want between the tags
By default, Jenkins stores all of its data in this directory on the file system.
There are a few ways to change the Jenkins home directory:
Edit the JENKINS_HOME variable in your Jenkins configuration file (e.g. /etc/sysconfig/jenkins on Red Hat Linux).
Use your web container's admin tool to set the JENKINS_HOME environment variable.
Set the environment variable JENKINS_HOME before launching your web container, or before launching Jenkins directly from the WAR file.
Set the JENKINS_HOME Java system property when launching your web container, or when launching Jenkins directly from the WAR file.
Modify web.xml in jenkins.war (or its expanded image in your web container). This is not recommended.
This value cannot be changed while Jenkins is running.
It is shown here to help you ensure that your configuration is taking effect.
If you go into Configure under Home there is a "Help" note on how to:
Home directory /var/lib/jenkins Help for feature: Home directory
By default, Jenkins stores all of its data in this directory on the file system.
There are a few ways to change the Jenkins home directory:
Edit the JENKINS_HOME variable in your Jenkins configuration file (e.g. /etc/sysconfig/jenkins on Red Hat Linux).
Use your web container's admin tool to set the JENKINS_HOME environment variable.
Set the environment variable JENKINS_HOME before launching your web container, or before launching Jenkins directly from the WAR file.
Set the JENKINS_HOME Java system property when launching your web container, or when launching Jenkins directly from the WAR file.
Modify web.xml in jenkins.war (or its expanded image in your web container). This is not recommended.
This value cannot be changed while Jenkins is running.
It is shown here to help you ensure that your configuration is taking effect.
def finder = new FileNameFinder()
def files = finder.getFileNames '\\pkg\\stage\\', '*.sln'
echo "$files"
jenkins is serching file in /var/lib/jenkins/pkg/stage
it is automatically adding /var/lib/jenkins path before

How to change the jenkins `/tmp` dir location?

How can I change the location where jenkins store temp data in its slaves. Currently, it shuts down the connection to my slaves because it complains about the following
Disk space is too low. Only 0.119GB left on /tmp.
I want to move the tmpdir location to something like /var/tmp/ instead of /tmp. How can I do that?
Just add "-Djava.io.tmpdir=/path/to/tmp" to the java command line options (you don't need any extra service wrapper).
Depending on your installation there might be an existing startup script and/or config file this can go into. On my fedora system, I can add the option to the /etc/sysconfig/jenkins file:
## Type: string
## Default: "-Djava.awt.headless=true"
## ServiceRestart: jenkins
#
# Options to pass to java when running Jenkins.
#
JENKINS_JAVA_OPTIONS="-Djava.awt.headless=true -Djava.io.tmpdir=/var/tmp"
On a debian/ubuntu machine, add the following to the file /etc/default/jenkins:
# use a different tmpdir for jenkins
JAVA_ARGS="$JAVA_ARGS -Djava.io.tmpdir=/var/tmp/"
If using "SSH Slaves Plugin", you can set JVM Options in "Advanced settings" and add:
-Djava.io.tmpdir=/my/temp
You can use Java Service Wrapper.
And config your wrapper(look example)
wrapper.java.additional.2=-Djava.io.tmpdir=../tmp
Or you can create symbolic link /var/tmp folder and put on home jenkins daemon.
On a Windows agent, assuming you have set it up as a Windows service wrapping a call to Java Web start, you should see a jenkins-slave.xml file in the agent's target folder.
You can edit this file and add -Djava.io.tmpdir=D:\Whatever\folder\ in the <arguments> tag to configure the temporary folder.
E.g.
<arguments>-Xrs -Djava.io.tmpdir=D:\Temp\ -jar "%BASE%\slave.jar" -jnlpUrl http://jenkins-master-whatever/slave-agent.jnlp -secret 999999999999999999999999999999999999999999999999999999999999</arguments>
You'll need to restart the service to see your modifications at work.
Running on FreeBSD, you can configure the temp directory by adding this line to your /etc/rc.conf:
jenkins_java_opts="-Djava.io.tmpdir=/var/tmp"
When jenkins is wrapped, e.g. bootstrapped as a windows service, add the configuration to the %JENKINS_HOME%\jenkins.xml <arguments> element
or on a slave, %JENKINS_HOME%\jenkins-slave.xml
Same information as other answers but official support article from CloudBees regading JNA error on Jenkins Master (although the same applies for Jenkins Nodes):
https://support.cloudbees.com/hc/en-us/articles/215281717-Jenkins-fails-to-start-with-JNA-error
To change the temporary directory that Jenkins uses, you need to:
append -Djava.io.tmpdir=$JENKINS_HOME/tmp into JENKINS_JAVA_OPTIONS variable in either /etc/sysconfig/jenkins or /etc/default/jenkins file depending on your OS
create /var/lib/jenkins/tmp using the Unix user that runs the Jenkins process
On modern Jenkins you can use UI option in the Jenkins Configuration which is called "Override temporary dir location"
On a slave you can just add it to the slaves advanced parameter in Jenkins -Djava.io.tmpdir=/var/tmp/

How to change home directory of Jenkins?

Simple question: How to change the jenkins home directory location? By default it points to /var/lib/jenkins whereas I want it to point to /home/jenkins. I have changed my $JENKINS_HOME to /home/jenkins but it doesn't help me.
For me on Jenkins 2.7.2 on RHEL 7.2 after already starting jenkins and configuring a build, I needed to:
1) Change the jenkins user's home directory
sudo su -
service jenkins stop
vi /etc/passwd
# change the /var/lib/jenkins to /home/jenkins or whatever
2) Change the setting in the start script to also find it
vi /etc/sysconfig/jenkins
# change the JENKINS_HOME to /home/jenkins or what ever
3) Copy all the data to the new location (eg: /home/jenkins)
cd /home
cp -Rf /var/lib/jenkins .
chown -R jenkins:jenkins *
4) Start it back up
service jenkins start
And that seems to have done it for me.
To change the Jenkins home directory you just need to setup the "JENKINS_HOME" environment variable to point to the new location. You can also set the JENKINS_HOME as a system property or a JNDI environment entry as explained in the documentation.
Jenkins Documentation
Jenkins usually runs with its own user,
so changing the home-dir of that user should do the job.
If not sure, simply run a test-job with a shell-command like 'id' or 'whoami' or 'env' to find the user that Jenkins uses.
Also, note that a message of "Started by user anonymous" does not mean that Jenkins started as an anonymous user -
please see this related answers by Sagar and Peter Tran:
how to run jenkins as a different user
I am using Ubuntu server and using Jenkins version (2.277.4 +). I was able to change the Jenkins home directory by:
Changing the JENKINS_HOME value in /etc/default/jenkins to the desired folder name.
Update permission on the target folder so that jenkins user has read,write,execute permissions on the folder.
I tried setting the PATH thing but it doesn't seem to work as it probably has to be under Jenkins user which does not have a real unix user account. I found the variable also accessible in /etc/sysconfig/jenkins which did the trick when I restarted Jenkins.
[A] Find your current jenkins home folder, if you are not aware where it is ?
Jenkins -> Manage Jenkins -> Configure System -> Check label 'Home directory'
[B] To move current Jenkins home folder to a new directory. Follow below steps :-
Stop Jenkins service - by killing the process
Follow one of below approach to set new home folder for JENKINS.
a) By default Jenkins home directory is set to ~/.jenkins
b) "JENKINS_HOME" environment variable setup in operating system.
c) "JENKINS_HOME" entry in JNDI environment.
d) "JENKINS_HOME" system property to the servlet container.
Tomcat context descriptor of the servlet, you can set below field in apache-tomcat-8.5.28/conf/context.xml :
<Context ...>
<Environment name="JENKINS_HOME" value="/path/to/jenkins_home/" type="java.lang.String"/>
</Context>
e) If jenkins.war file is deployed in a tomcat server , then even appending below content in bin/catalina.sh will setup JENKINS_HOME.
CATALINA_OPTS="-DJENKINS_HOME=/path_to/jenkins_home/"
Manually copy Jenkins home folder content from old to new home
folder. (In windows , ctrl + c / v . In Unix ,
use cp command) . Instead of moving, copy step is advised to keep one backup. Later we can delete old workspace.
Now start Jenkins, then It will pick the new home directory
from the path mentioned in JENKINS_HOME variable.
Note: - Just by setting above variable "JENKINS_HOME" to a different path will not copy
the files from current Jenkins home path to new one automatically. This copy step - you have to do it yourself, Manually.
Follow steps:
sudo su
service jenkins stop
nano /etc/default/jenkins
change JENKINS_HOME variable to whatever folder you want
save it
service jenkins start*

Resources