4
votes

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.

5
Restarting the service should be sufficient, you don't need to reload the configuration as well. Can you provide more detail on what files you copied, where you copied them from and what destination you copied them to ? You may also find some clues in the Jenkins log file.gareth_bowles
@gareth_bowles I edited my post, please check it out.ChocoDeveloper
@gareth_bowles Reading the logs more carefully solved this, thanks! See my answer.ChocoDeveloper

5 Answers

6
votes

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.

2
votes

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.

1
votes

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'

0
votes

If you want to copy jobs from other jenkins,

Just copy the $JENKINS_HOME/jobs//config.xml to your new $JENKINS_HOME/jobs, and then reload configuration from disk.

0
votes

I think from the above answers that you didn't copy the configuration files for the individual jobs. The JENKINS_HOME directory is laid out like this:

$JENKINS_HOME contains system level configuration files such as the Jenkins master config.xml and the credentials.xml

$JENKINS_HOME/jobs contains all the individual job configuration and build data in a separate subdirectory for each job, e.g. for the job "myjob" you'll have $JENKINS_HOME/jobs/myjob/config.xml plus other files that store the data for individual builds.

So if you want to restore the system configuration and all the jobs without the build history, you'll need to copy:

$JENKINS_HOME/.xml $JENKINS_HOME/jobs/*/config.xml (using Antglob notation, ** denotes all subdirectories under $JENKINS_HOME/jobs)

You'll also need $JENKINS_HOME/plugins/* if you installed any extra plugins.

If you want to restore all the build history, copy $JENKINS_HOME/jobs/* instead of just the config.xml files.