Changing JENKINS_HOME in /etc/sysconfig/jenkins not working - jenkins

So I wanted to change the default JENKINS_HOME location. I pretty much always found the "edit the jenkins configuration" solution so I did that. I followed this guide https://phoenixnap.com/kb/change-jenkins-home-directory
Seemed legit, but it didn't work. /var/lib/jenkins is still JENKINS_HOME. I also tried setting a env var but that too did not work...
Does anyone have any clues as to why the configuration at /etc/sysconfig/jenkins is not being read/loaded?

Thanks for Ian W. This is a system bug that requires modification of the startup script.
vim /usr/lib/systemd/system/jenkins.service
systemctl daemon-reload
systemctl restart jenkins.service
Managing systemd services

Related

Timeout during Jenkins plugin installation

I try to install an old version of Jenkins (2.346.3 downloaded here ) because i need a java 8 compatible Jenkins.
Everything goes well while this screen :
I clic on Install suggested plugins and few seconds later I have this message :
With a standard installation there is the solution to increase the value of pluginManagerErrorTimeoutMillis in the file pluginSetupWizard.js as explained here
But with my installation the file pluginSetupWizard.js is minified and not in the /var/lib/jenkins directory.
So I tried to modify the files
/var/cache/jenkins/war/jsbundles/plugin-manager-ui.js.map
/var/cache/jenkins/war/jsbundles/pluginSetupWizard.js.map
Because they contain the variable pluginManagerErrorTimeoutMillis
then I do
systemctl daemon-reload
systemctl stop jenkins
systemctl start jenkins
but it does not work
I am currently stuck so do you know how can I increase this timeout in order to finish the jenkins installation ?
EDIT
So I found the solution :
I change the value in
/var/cache/jenkins/war/jsbundles/plugin-manager-ui.js
o=1e4 to o=1e6
and it works.
But I think this value should be increased by default in Jenkins.

Jenkins: allow local checkout

It's the first time I'm using Jenkins. I created a new folder with just one file and created a git repository in it. Then I set up Jenkins with that repository.
What I get now is this error:
ERROR: Checkout of Git remote 'path\hello' aborted because it
references a local directory, which may be insecure. You can allow
local checkouts anyway by setting the system property
'hudson.plugins.git.GitSCM.ALLOW_LOCAL_CHECKOUT' to true. Finished:
FAILURE
I tried to start jenkins using this command:
C:\Users\userName\.jdks\zulu11.56.19-ca-jdk11.0.15-win_x64\bin\java.exe -jar jenkins.war hudson.plugins.git.GitSCM.ALLOW_LOCAL_CHECKOUT=true
But it didn't work.
How can I set this "allow local checkout" to true?
Define properties using option -D:
-Dhudson.plugins.git.GitSCM.ALLOW_LOCAL_CHECKOUT=true
In my case I am running Jenkins on WSL2 (Ubuntu), I edited the file "jenkins" located at /etc/default, added the line:
JAVA_ARGS="-Dhudson.plugins.git.GitSCM.ALLOW_LOCAL_CHECKOUT=true"
right below an existing line, like so:
# Allow graphs etc. to work even when an X server is present
JAVA_ARGS="-Djava.awt.headless=true"
JAVA_ARGS="-Dhudson.plugins.git.GitSCM.ALLOW_LOCAL_CHECKOUT=true"
After saving the file, did a "service jenkins restart" and it worked for me, now whenever Jenkins is started I don't have to specify the option manually.
I have faced the same issue the solution was:
-Dhudson.plugins.git.GitSCM.ALLOW_LOCAL_CHECKOUT=true needs to be BEFORE -jar jenkins.war in the command line call.
The solution is provided from the below recourse:
https://community.jenkins.io/t/checkout-of-git-remote-aborted-because-it-references-a-local-directory/4110
For Ubuntu edit config:
sudo gedit /lib/systemd/system/jenkins.service
Add line:
Environment="JAVA_OPTS=-Dhudson.plugins.git.GitSCM.ALLOW_LOCAL_CHECKOUT=true"
Restsart service:
service jenkins restart
systemctl daemon-reload
Check config:
systemctl cat jenkins
For RedHat/CentOS, edit config file at: /etc/sysconfig/jenkins
Find: JENKINS_JAVA_OPTIONS="-Djava.awt.headless=true"
Add below:
JENKINS_JAVA_OPTIONS="-Dhudson.plugins.git.GitSCM.ALLOW_LOCAL_CHECKOUT=true"
Then restart: sudo systemctl restart jenkins

How to get Jenkins to use a proxy when updating plugins

I am running a setup where Jenkins is running behind ngnix, but jenkins needs to use a bluecoat proxy to update plugins.
I have tried updating the advanced proxy settings page but it is not working and have verified that I can wget http://mirror.xmission.com/jenkins/updates/current/update-center.json when I have the http_proxy and https_proxy system variables.
I have also tried updating /etc/profile as I see that /etc/init.d/jenkins that they use su jenkins -l when starting Java
Thanks,
Walt
I had the same issue.
The way that I solved it was to edit /etc/default/jenkins and update JAVA_ARGS to use my proxy
JAVA_ARGS="-Djava.awt.headless=true -Dhttp.proxyHost=foo.proxy.com -Dhttp.proxyPort=80 -Dhttps.proxyHost=foo.proxy.com -Dhttps.proxyPort=80"
cheers,
Stephen

Change JENKINS_HOME on Red Hat Linux?

I used this procedure to install Jenkins:
https://wiki.jenkins-ci.org/display/JENKINS/Installing+Jenkins+on+RedHat+distributions
After it was up and running I discovered the /var/lib/jenkins partition on my server is very small. I want to move it, but I do not want to change the user that it runs under. I am new to Linux and I'm stumped. How do I move it for example to my Home/Public folder? The "Jenkins" user doesn't seem to have a Home folder. Its running as a daemon on startup, so I have no idea where to configure those settings.
Can I create a Home folder for the Jenkins user? How?
I read this article:
https://wiki.jenkins-ci.org/display/JENKINS/Administering+Jenkins
but do not understand HOW to "set the new Jenkins home". I have used the export command, and restarted the service, but the old path still shows up in the Manage Jenkins screens.
I've read the 2-3 similar questions on stackoverflow also, but there's always a big missing piece for me. Where to find that file where I change the path permanently?
Here's an easy way to solve your problem. First, move the Jenkins directory from /var/lib/jenkins to /home/jenkins. Then create a symlink at /var/lib/jenkins pointing to /home/jenkins. And of course, stop the Jenkins service before doing that.
sudo service jenkins stop
sudo mv /var/lib/jenkins /home
sudo ln -s /home/jenkins /var/lib/jenkins
sudo service jenkins start
I managed to change the home location for Jenkins by modifying content of /etc/sysconfig/jenkins file as follows:
JENKINS_HOME="/home/jenkins"
Okay, I reread your question a little bit more closely, lets see if we can figure this out. I am going to list some info that you may or may not know.
The jenkins installation and jenkins home are not the same thing. One is where the war file and other parts that jenkins needs to run live. jenkins_home is where your data is stored. By default, jenkins_home lives in ~/.jenkins. When you start jenkins, it looks for an environment variable to tell it where to find those files.
Jenkins runs as a seperate user, which, by default, is jenkins. This way it doesn't get in the way of you. The jenkins user will not have access to YOUR home directory, so that would be a poor solution. Ideally, it would have its own home directory, /home/jenkins. Your home directory could then be /home/jenkins/.jenkins. You say that folder doesn't exist- if you don't have access to it to create it yourself, that is perfectly fine, you can specify ANY folder. However, the jenkins user must have ownership of that folder to read and write to it.
It looks like Jenkins on redhat will be running with tomcat by default. The documentation for how to set environment variables for tomcat is https://wiki.jenkins-ci.org/display/JENKINS/Tomcat
This all gets set up with a script.https://wiki.jenkins-ci.org/display/JENKINS/JenkinsLinuxStartupScript seems to be the one that is used for this purpose. Even if you don't know anything about shell scripting, this isn't too hard... lines with a # are comments. The first line
JENKINS_USER=jenkins
sets the name of the user account jenkins will be using. Look down a littlle further, and you'll see the line
export JENKINS_BASEDIR=/home/jenkins
export CATALINA_OPTS="-DJENKINS_HOME=$JENKINS_BASEDIR/jenkins-home -Xmx512m -Djava.awt.headless=true"
This lets you set a directory to where jenkins should live, and then sets the jenkins_home directory to that /jenkins-home.
For your application, you may want to do something like this
export CATALINA_OPTS="-DJENKINS_HOME=/var/jenkinsmount/home -Xmx512m -Djava.awt.headless=true"
That would then store all of your build data (which is the part that grows!) at /var/jenkinsmount/home ... while leaving the rest of your files in their current location.
I haven't used it on redhat, but hopefully I explained enough for you to actually understand what is going on so that you can get it going!
Other INFO:
https://wiki.jenkins-ci.org/display/JENKINS/Installing+Jenkins+as+a+Unix+daemon
I have faced the same issue and question.
Connecting some dots I could fix my Jenkins after I moved Jenkins to a new location due to the same issue -space in disk under /var/lib/jenkins.
Here is the procedures that I had to follow to get it working taking in consideration that I am pointing Jenkins to a non-default port. (I have applied this process into 2 servers)
First, move the Jenkins directory from /var/lib/jenkins to /opt/jenkins
sudo service jenkins stop
sudo mv /var/lib/jenkins /opt/
Now you can change your workspace and build directory to any other location on your machine.
Jenkins provides 3 predefined variables that can be used to specify the new location:
JENKINS_HOME — Jenkins home directory
ITEM_ROOTDIR — Root directory of a job for which the workspace is allocated
ITEM_FULLNAME — ‘/’-separated job name, like “foo/bar”
sudo su jenkins (access as Jenkins user)
JENKINS_HOME=/opt/jenkins
ITEM_ROOTDIR=/opt/jenkins
ITEM_FULLNAME=/opt/jenkins
exit (exit Jenkins user)
Now, edit the jenkins config
/opt/jenkins$ sudo nano /etc/default/jenkins
Modify the following line
#jenkins home location
#JENKINS_HOME=/var/lib/$NAME (here is the default)
JENKINS_HOME=/opt/jenkins (that is our new location)
change the home directory of a user
sudo usermod -d /opt/jenkins/ jenkins
sudo service jenkins start
If anyone is having issues with space and you have to relocate your jenkins, just wanted to reiterate that::
sudo service jenkins stop
sudo mv /var/lib/jenkins /home
sudo ln -s /home/jenkins /var/lib/jenkins
sudo service jenkins start
works great, so thanks to the person who posted that answer a few years ago!
Richard Chen's location is where I found the jenkins file on my CentOS 6.6 system.
sudo service jenkins stop
mv /var/lib/jenkins /home/mylocation/
(made sure the new location had correct ownership and group-- Jenkins)
modified the content of the file /etc/sysconfig/jenkins as follows:
JENKINS_HOME="/home/mylocation"
sudo service jenkins start
If all these don't work, then the only solution that works is to edit the following file
/lib/systemd/system/jenkins.service
then need to execute reloading of configs by running
systemctl daemon-reload
after this restarting the service would reflect the change.
Some commands work for me as below:
Step 1: Stop jenkin service and moving folder
systemctl stop jenkins
mv /var/lib/jenkins /whatever/folder
sudo chown jenkins -R /whatever/folder
Step 2: Modify jenkins home location in /etc/default/jenkins
JENKINS_HOME=/whatever/folder/$NAME
Step 3: Restart jenkins service
systemctl start 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. (use cp command) . Instead of moving, copy step is advised to keep one backup. Later you 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.

Jenkins website root path

I'm trying to follow the directions here: https://wiki.jenkins-ci.org/display/JENKINS/Running+Jenkins+behind+Apache to set up my Jenkins server to appear at http://myhost/jenkins. It works, but the Jenkins website thinks http://myhost/ is the jenkins/ root.
I believe this problem is caused by the first warning flag on that web page, i.e. that my context path is not set correctly. However, I can't figure out where to set the context path. The instructions for ubuntu and windows are clear enough, but on Mac OS X 10.6, there is no jenkins.xml file, no /etc/default/jenkins file, and nothing of relevance I can see in ~/.jenkins/config.xml.
So, what am I missing? Where can I tell jenkins that its root is in /jenkins/ instead of /?
Paraphrasing from the document you mentioned;
You need to specify the context/prefix of the Jenkins instance, this can be done by modifying the Jenkins configuration as follows;
Either, set the context path by modifying the jenkins.xml configuration file and adding --prefix=/jenkins (or similar) to the entry.
Or Set the context path when using by adding --prefix=/jenkins to JENKINS_ARGS in /etc/default/jenkins (Ubuntu) or in an appropriate startup file.
So, how to find these things...
The Jenkins.xml file should be in the $JENKINS_HOME directory, I'm not sure if Mac OS has the "updatedb" and "locate " commands, but you could try doing updatedb && locate jenkins.xml
Also, have a look in the startup scripts; /etc/init.d if installed from a package, or add the JENKINS_ARGS to the environment properties for the User running Jenkins (append to ~user/.profile) or the arguments for the container running Jenkins.
Be aware that if your Jenkins installation (without the prefix argument) was running under:
http://myserver:8080/ => 200 Jenkins is here
adding --prefix=/ci/dashboard in the arguments will produce this behaviour:
http://myserver:8080/ => 404
http://myserver:8080/ci/dashboard => 200 Jenkins is now here
Not sure where to look in config.xml, but at http://myhost/jenkins/configure, there's an option called "Jenkins URL" that you can use to set that.
Just to provide some recent confirmation of the suggested approaches, on CentOS 7, with Jenkins 1.610, I was able to achieve this by changing jenkinsUrl in jenkins.model.JenkinsLocationConfiguration.xml to the desired one (e.g. http://127.0.0.1:8080/jenkins), adding
JENKINS_ARGS="--prefix=/jenkins"
inside /etc/sysconfig/jenkins, and restarting Jenkins.
FYI the Jenkins installation was made via Puppet, using this Puppet module.
Add prefix attribute to /etc/default/jenkins file:
JENKINS_ARGS="--webroot=/var/cache/jenkins/war --prefix=/jenkins --httpPort=$HTTP_PORT --ajp13Port=$AJP_PORT
Configure your web server (e.g. - nginx) to redirect /jenkins to localhost:8080;
Put this into /etc/apache2/other/jenkins.conf:
ProxyPass /jenkins http://localhost:8009/jenkins
ProxyPassReverse /jenkins http://localhost:8009/jenkins
ProxyRequests Off
<Proxy http://localhost:8009/jenkins*>
Order deny,allow
Allow from 127.0.0.1
</Proxy>
Then execute these commands:
sudo defaults write /Library/Preferences/org.jenkins-ci httpPort 8009
sudo defaults write /Library/Preferences/org.jenkins-ci prefix /jenkins
sudo launchctl stop org.jenkins-ci
The last command tells launchd to stop the running instance of Jenkins. And a new one will automatically be started because the launchd has been configured to always keep Jenkins running.
This is how I fixed it under Debian Wheezy running Jenkin 1.557
in /etc/default/jenkins , modify the JENKINS_ARGS line by adding "--prefix=$PREFIX"
JENKINS_ARGS=" ..... --prefix=$PREFIX"
you need to edit jenkins config file in directory
such like :
sudo vi /etc/default/jenkins and change var HTTP_PORT
next restart jenkins
sudo /etc/init.d/jenkins restart
hope this is helpful
I'm using CentOS7, add JENKINS_ARGS="--prefix=/jenkins" to /etc/sysconfig/jenkins and restart Jenkins worked. Then you can visit via ip:8080/jenkins
I'm not sure if people are still looking for this, but as I just ran across it, I figured I'd post my solution here.
By following the instructions at here, I was able to set the context located in Library/Preferences/org.jenkins-ci.plist to a more preferable address. The link has all the settings you can edit with an OS X native install.
I needed to configure Jenkins on a CentOS box via Puppet using the rtyler/jenkins module. Looking through the module code might suggest that HTTP_PORT and PREFIX should be the parameters in the config_hash but this did not work for me. What worked for me was something like the following Puppet configuration:
class { 'jenkins':
config_hash => {
'JENKINS_PORT' => { 'value' => '8085' },
'JENKINS_ARGS' => { 'value' => '--prefix=/jenkins' },
},
}
I was able to confirm that this updated the contents of "/etc/sysconfig/jenkins" (I believe this is the CentOS/RedHat file location).
For a Windows installation add the prefix within the <arguments> tag (jenkins.xml) and restart the service (Powershell Restart-Service jenkins). E.g.:
<executable>%BASE%\jre\bin\java</executable>
<arguments>-Xrs -Xmx256m -Dhudson.lifecycle=hudson.lifecycle.WindowsServiceLifecycle -jar "%BASE%\jenkins.war" --httpPort=8080 --webroot="%BASE%\war" --prefix=/jenkins</arguments>

Resources