Jenkins - Disappears all jobs after restart - jenkins

The jenkins version is :
<version>2.186</version>
<installStateName>RESTART</installStateName>
<numExecutors>2</numExecutors>
<mode>NORMAL</mode>
All jobs disapperad after restart jenkins : sudo service jenkins restart
/var/lib/jenkins/config.xml includes them. The config file has no conflict. I have checked it using an xml validator.
How can I fix it? There is no job in jenkins dashboard.

Either option will work
1)
choose option reload configurations from disk (Manage Jenkins/Reload Configuration from Disk).
Or
2) Can you try to install Stable Jenkins and import all jobs n folder structure to new jenkins folder structure.
Hope that might help if by mistakenly someting is courupted or deleted in current folder structure of jenkins.
I had same issue I solved it using above method

I would first check folder permissions:
stat /var/lib/jenkins/jobs
stat /var/lib/jenkins
Then I would change permissions if needed:
chown -R your_user /var/lib/jenkins
You will need to restart Jenkins and maybe reboot the machine.

Related

Artifact Deployer Plugin Alternative

We are using the artifact deployer plugin in a Jenkins freestyle job, and recently Jenkins is displaying warnings about the plugin no longer being safe to use.
This plugin is no longer being distributed according to their wiki site here
Does anyone know of any alternative plugins, or ways in a freestyle job to copy content from one location to another (on same node)
Thanks
To copy all the contents from one directory to another directory in a Linux system use the following command:
cp -a /path/to/source_dir/. /path/to/dest_dir/
You can add an Execute shell step in in your job configuration in Build section and add the above command into it.

Jenkins - Backup Configuration of Job

I want to backup configuration of job, I am using to do this ThinBackup plugin in version 1.7.4 . And in every configuration of the job, there is something like Promote builds when.., how to backup this?
I ran into same issue and found this is an open bug. Looks to have a fix but a new version of the plugin hasn't been released.
A workaround which seems to work OK so far, is to separately backup the config.xml files under the JENKINS_HOME/jobs/. On Linux I ran the below from the Jenkins home directory to create this additional backup:
$ find jobs -name config.xml -exec tar -rzvf /tmp/config.xml-BACKUP.tgz {} \;
So I'm still using ThinBackup to get all the other bits but after restoring its backup:
tar -xzf /tmp/config.xml-BACKUP.tgz
I then restored the jobs config.xml backup and restarted Jenkins.
They are a some options with the ThinBackup plugin:
Did you try to enable the "Backup build archive" option?

How to disable security checking in Jenkins?

In any answer and in jenkins website tell me to set
<useSecurity>true</useSecurity>
in config.xml but in my jenkins folder don't have this file
config.xml doesn't get written until server is restarted at least once since installation.
Try restarting the Jenkins server.
This likely sounds like invalid Jenkins installation, or the file is in another place pointed by $JENKINS_HOME or $CATALINA_OPTS (e.g. ~/.jenkins or /var/usr/jenkins/.jenkins).
Another reason could be that by default Jenkins load all data from memory and you need to reload the configuration files from file system, so try restarting Jenkins.
Then double check in System Properties (at /systemInfo) that user.home points to the folder where you expect that file. Check also your System Log (/log/all) for any issues.
If above won't help, check the folder permission and if there is enough space (but you should have some error anyway). Or try reinstalling Jenkins.
According to Administering Jenkins documentation page, the config.xml Jenkins root configuration should be always in your JENKINS_HOME folder.
Once you've got config.xml, to disable security remove the lines with useSecurity and authorizationStrategy and restart Jenkins, or try executing these commands:
sudo ex +g/useSecurity/d +g/authorizationStrategy/d -scwq /var/lib/jenkins/config.xml
sudo /etc/init.d/jenkins restart

How to download a file from the jenkins job build folder

I have a jenkins server running, and for a job I need to download a file which is in the jobs/builds/buildname folder.
How to download that file from jenkins job?
If you would use the workspace as suggested by previous post, you can access it within a Pipeline:
sh "wget http://<servername:port>/job/<jobname>/ws/index.txt"
Or inside a script:
wget http://<servername:port>/job/<jobname>/ws/index.txt
Where index.txt is the file you want to download.
I rock a Unix based development machine and a Unix based Jenkins machine up in the cloud. This means I can use the SCP Command to download the remote file over an ssh connection. This is the anatomy of my scp commands:
scp -i <path/to/ssh.pem/file> <user>#<jenkins.remote.url>:<path/to/remote/file> <local/path/where/download/goes>
This works for directories too, for instance I use this to download backups generated by the ThinBackup Plugin
You had already been given the answer for getting the file from the workspace
http://<servername:port>/job/<jobname>/ws/filename.ext
Obviously replace stuff in <..> with values relevant to your setup, and make sure anonymous user has access to read from workspace, else you may have to login.
The only other files you could access are those that are archived from previous job runs.
http://<servername:port>/job/<jobname>/<buildnumber>/artifact/filename.ext
Where <buildnumber> is the build number you see in job build history, or one of the permalinks provided by Eldad (such as lastStableBuild). But this will only have access to archived artifacts.
You cannot arbitrarily access files from Jenkin's filesystem through the web interface... it wouldn't be very secure if it did let you.
The Jenkins job's build folder is meant for logging and plugins reports. You should not need to access it directly.
If you must, you can access it relative to the workspace: $WORKSPACE/../builds/$BUILD_ID/
You can also replace the $BUILD_ID with one of the links Jenkins creates:
lastFailedBuild
lastStableBuild
lastSuccessfulBuild
lastUnstableBuild
lastUnsuccessfulBuild
I hope this helps.
As others have pointed out this path should work, I like to highlight that the "ws" is a directory in Jenkins:
http://<servername:port>/job/<your job>/ws/<your file>
Download the Package lynx (Command line browser)
$ apt-get install lynx
or
$ yum install lynx
then use the command
# lynx http://<servername:port>/job/<jobname>/ws/file
The App Will Ask you to allow cookies and if there are authentication will direct you to login page like the browser.

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