Friday, 22 May 2015

How to backup a Jenkins job into a XML file

Jenkins has a built-in command line client that allows you to access Jenkins from a script or from your shell.

So, first of all you need to download a JAR file. See http://yourserver.com/cli for where to download the CLI jar file.

After that you can run the below command in your linux shell to export your Jenkins job:

java -jar jenkins-cli.jar -s http://yourserver.com/ get-job your-job-name --username your-username --password your-password > your-job-name.xml

Thats all, you will get a XML file named "your-job-name.xml" with all the content ready to be imported in another Jenkins server.

If you want to import your XML file into your local Jenkins server, you need to run the following command:

java -jar jenkins-cli.jar -s http://localhost:8080/ create-job your-job-name < your-job-name.xml

No comments:

Post a Comment