How to migrate jobs from one Jenkins build server to another
Prachi is a senior DevOps Engineer specializing in designing, implementing and maintaining production web applications on AWS Cloud/Docker.
I recently set-up a new Jenkins server with the latest stable release to check some new plugins and I wanted to find a quick way to migrate jobs from my existing old server to the new one.
My source Jenkins is dockerized and the target one is a standalone build server.
Now there are multiple ways in which this could be achieved.
- Use Jenkins Plugin
- Use Jenkins CLI
- Copy the jobs directory from the source to the target Jenkins server and reload the configuration from disk
Use Jenkins’ Import Job Plugin
Below is a snapshot from the Jenkins plugins page listing the job import plugin. Install the plugin and restart Jenkins, observe if there are any errors during installation and verify if the installation was successful.
If the installation went fine, you should see below plugin configuration section in 'Manage Jenkins'.
Go to Manage Jenkins --> Configure System --> Job Import Plugin
Add the remote source server details.
This is an important step. Make sure your user is set to import the jobs with the right permissions.
Also, on the source server, it is recommended that the ‘Authenticated Users’ have at least read/discover/workspace permissions for the jobs.
If the plugin installation went well and Jenkins is restarted, the plugin is displayed on the left pane as below
Open the above link and notice the options below. If the plugin configuration went well in above steps, the remote Jenkins server (source server) is automatically displayed in the drop-down list. If not, you may want to revisit the URL/credentials section above again to check the issue.
You can fire the query and wait for a couple of minutes for the results to be displayed.
Here I have all my jobs enlisted in the query results. I chose to import the jobs and install the plugins as well.
This successfully copies the jobs and plugin configurations, however if you want to migrate your workspace data, that needs to be copied to the respective workspace location from the source to the target.
Else you’re good to go.
We’ll continue to explore the other methods ahead…