Backup and Store Jenkins Jobs and Configuration in Source Control such as GIT or SVN

Article ID:215866318
2 minute readKnowledge base

Issue

  • I would like to automatically check-in and backup my Jenkins jobs via GIT. How can I manage separate controllers with different jobs that move between the controllers?

  • I would like manage plugin versions in a source control system.

Environment

  • CloudBees Jenkins Enterprise

  • CloudBees Jenkins Operations Center

Resolution

There are several options, depending on your organization’s SCM configuration and specific needs:

1) Use CloudBees Backup Plugin to take a "Local directory" backup which would be a snapshot of your $JENKINS_HOME/jobs/ directory. From here you can store the data in SCM for version control/history and disaster recovery purposes.

2) Use the Workflow Multibranch Feature provided by the Pipeline Plugin. It requires the workflow definition to be stored in a Jenkinsfile in the project and will use it to build your project. As the job configuration is stored in the SCM, it can be moved to another controller.

3) If you need to perform backups of your controllers, you could also use a Cluster Operation on your CloudBees Jenkins Operations Center instance to generate and gather the backups on all connected controllers.

4) To capture plugin versions on your CloudBees Jenkins Enterprise (Client controller), you can use the run the Jenkins CLI to do this: java -jar jenkins-cli.jar -s ${JENKINS_CONTROLLER_URL} list-plugins (append > myinstance_plugins.txt " to this command to capture the output as a text file, from which you can check-in to source control)

If you have CloudBees Jenkins Operations Center, you can similarly capture plugin versions: java -jar jenkins-cli.jar -s ${CJOC_URL} list-plugins

This command will return the job definition XML to stdout which includes the <pluginsData> section that does contain all of the plugins available on the Update Center: java -jar jenkins-cli.jar -noKeyAuth -s ${CJOC_URL} get-job CustomUpdateCenter