Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to restore jobs in Jenkins?

Tags:

jenkins

In the docs it says that all you have to do is copy the files or folders. But when I do that and then try to restore by restarting the service and using the GUI Manage Jenkins > Reload Configuration from Disk (btw, is there a way to do this programatically?), only the credentials are restored (they come from credentials.xml which I also copied). No jobs are listed.

Any ideas?

Edit:

I created a directory /var/lib/jenkins/jobs/myjob and inside it I dropped the "config.xml" file. That file used to be in the previous instance of my server, on the same location.

I also dropped the old "credentials.xml" into /var/lib/jenkins. That worked fine, I can see the credentials in the web interface.

like image 299
ChocoDeveloper Avatar asked May 22 '14 00:05

ChocoDeveloper


3 Answers

To restore jobs in Jenkins, you just need to copy jobs/ folder into new Jenkins HOME folder (only config.xml files is enough) and make sure you've all necessary plugins (in Linux it's /var/lib/jenkins/).

For Jenkins root configuration, you need to copy config.xml from the main HOME directory (e.g. /var/lib/jenkins/config.xml). All other XML files are just site-wide and plugin configuration files (which may be copied as well).

For more details, check the following Jenkins directory structure:

JENKINS_HOME
 +- config.xml     (jenkins root configuration)
 +- *.xml          (other site-wide configuration files)
 +- userContent    (files in this directory will be served under your http://server/userContent/)
 +- fingerprints   (stores fingerprint records)
 +- plugins        (stores plugins)
 +- workspace (working directory for the version control system)
     +- [JOBNAME] (sub directory for each job)
 +- jobs
     +- [JOBNAME]      (sub directory for each job)
         +- config.xml     (job configuration file)
         +- latest         (symbolic link to the last successful build)
         +- builds
             +- [BUILD_ID]     (for each build)
                 +- build.xml      (build result summary)
                 +- log            (log file)
                 +- changelog.xml  (change log)

Source: Administering Jenkins - JENKINS_HOME directory

See also: Is there a way to keep Hudson / Jenkins configuration files in source control?


To reload configuration from the disk, use Reload Configuration from Disk option in Manage Jenkins. From Jenkins CLI, try reload-configuration command to discard all the loaded data in memory and reload everything from file system.

like image 114
kenorb Avatar answered Nov 13 '22 08:11

kenorb


I deployed the jobs (and plugins and credentials) using the deploy user and forgot to set the ownership to jenkins:jenkins.

I realized this by reading the Jenkins logs at /var/log/jenkins/jenkins.log, there were some "Permission denied" messages.

like image 34
ChocoDeveloper Avatar answered Nov 13 '22 09:11

ChocoDeveloper


In case you mistakenly changed job configuration in your Jenkins service/docker still running ,you can revert the configuration from web GUI using job configuration history plugin

Jenkins -> Job -> Job Config History -> Select radio buttons of correct version And bad version -> Show diffs (xml diff versions) -> select the right version and press 'restore this configuration'

like image 41
avivamg Avatar answered Nov 13 '22 08:11

avivamg