You can also use jenkins cli, I noticed non of these answers had mentioned this method.
- First download the Jenkins CLI jar.
- You can do this from your jenkin's CLI page within your installed Jenkins instance.
- Next we can use the following command (pointing to the old server) to list the jobs.
java -jar jenkins-cli.jar -s http://<YourBuildServer>:<YourBuildServerPort>/ list-jobs
- Using one job from the list above, let's copy the xml of a job to the clipboard. (I'm using a Mac which is were pbcopy & pbpastecome from below)
java -jar jenkins-cli.jar -s http://<YourBuildServer>:<YourBuildServerPort>/ get-job "NAME_OF_JOB" | pbcopy
This uses the cli get-job "NAME_OF_JOB" command to print the job's xml to stdout, which we pipe to pbcopy on the Mac to load the configuration into the clipboard. You could of course pipe the output to a file like ... > job.xml
- If the above command placed a job's XML into the clipboard, you can use the below command to add it to the new server.
pbpaste | java -jar jenkins-cli.jar -s http://<YourBuildServer>:<YourBuildServerPort> create-job "NAME_OF_JOB"
This uses pbpaste to take what is in the clipboard, send it to stdin and pipe it to the Jenkins cli's create-job "NAME_OF_JOB"command.