1 min read

How to export / import jobs in Jenkins?

How to export / import jobs in Jenkins?

Well, there's two ways to doing this. One is by the GUI and another is definitely the CLI way of getting things done.

Easy Method:

Jenkins has a rather good wiki, albeit hard to read when you're new to CI software...

They offer a simple solution for moving jobs between servers.

The trick probably was the need to reload config from the Jenkins Configuration Page.

Update 2020.03.10

The JenkinsCI landscape has changed a lot... I've been using Job DSL for a while now. We have a SEED Job that generates the rest of the jobs.

This helps us both recreate or move for the Jenkins server whenever needed :) You could also version those files for even more maintainability!

Tedious method:

Probably another method is to use Jenkins command line is another option, see https://wiki.jenkins-ci.org/display/JENKINS/Jenkins+CLI

  • create-job: Creates a new job by reading stdin as a configuration XML file.
  • get-job: Dumps the job definition XML to stdout

So you can do

java -jar jenkins-cli.jar -s http://server get-job myjob > myjob.xml
java -jar jenkins-cli.jar -s http://server create-job newmyjob < myjob.xml

Let me know what works best for you in the comments!