Butler CLI:Export/Import Jenkins Plugins & Jobs

Not long ago, I had to migrate Jenkins jobs from an old server to a new one. That’s where StackOverflow comes into the play, below the most voted answers I found:

  • Jenkins CLI
  • Copy the jobs directory
  • Jenkins Remote API
  • Jenkins Job Import Plugin

In spite of their advantages, those solutions comes with their downsides especially if you have a large number of jobs to move or no access root to the server. But, guess what ? I didn’t stop there. I have came up with a CLI to make your life easier and export/import not only Jenkins jobs but also plugins like a boss.

To get started, find the appropriate package for your system and download it. For linux:

1
2
3
wget https://s3.us-east-1.amazonaws.com/butlercli/1.0.0/linux/butler
chmod +x butler
mv butler /usr/local/bin/

Note: For Windows make sure that butler binary is available on the PATH. This page contains instructions for setting the PATH on Windows.

Once done, verify the installation worked, by opening a new terminal session and checking if butler is available :

1
butler help


1 – Plugins Management

To export Jenkins jobs, you need to provide the URL of the source Jenkins instance:

1
butler plugins export --server localhost:8080 --username admin --password admin


As shown above, butler will dump a list of plugins installed to stdout and a new file plugins.txt will be generated, with list of installed Jenkins plugins with name and version pairs:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
bouncycastle-api@2.16.2
structs@1.10
script-security@1.39
scm-api@2.2.6
workflow-step-api@2.14
workflow-api@2.24
workflow-support@2.16
durable-task@1.17
workflow-durable-task-step@2.17
credentials@2.1.16
ssh-credentials@1.13
plain-credentials@1.4
credentials-binding@1.13
gradle@1.28
pipeline-input-step@2.8
apache-httpcomponents-client-4-api@4.5.3-2.0
junit@1.23
windows-slaves@1.3.1
display-url-api@2.2.0
mailer@1.20
matrix-auth@2.2
antisamy-markup-formatter@1.5
matrix-project@1.12
jsch@0.1.54.1
git-client@2.7.0
pam-auth@1.3
authentication-tokens@1.3
docker-commons@1.11
ace-editor@1.1
jquery-detached@1.2.1
workflow-scm-step@2.6
workflow-cps@2.42
docker-workflow@1.14
jackson2-api@2.8.10.1
github-api@1.90
git@3.7.0
workflow-job@2.12.2
token-macro@2.3
github@1.28.1

Now, to import the plugins to the new Jenkins instance, use the command below with the URL of the Jenkins target instance as an argument:

1
butler plugins import --server localhost:8080 --username admin --password admin


Butler will install each plugin on the target Jenkins instance by issuing API calls.

2 – Jobs Management



To export Jenkins jobs, just provide the URL of the source Jenkins server:

1
butler jobs export --server localhost:8080 --username admin --password admin


A new directory jobs/ will be created with every job in Jenkins. Each job will have its own configuration file config.xml.



Now, to import the jobs to the new Jenkins instance, issue the following command:



1
butler jobs import --server localhost:8080 --username admin --password admin


Butler will use the configuration files created earlier to issue API calls to target Jenkins instance to create jobs.

Once you are done, check Jenkins and you should see your jobs successfully created :



Hope it helps ! The CLI is still in its early stages, so you are welcome to contribute to the project in GitHub.

Drop your comments, feedback, or suggestions below — or connect with me directly on Twitter @mlabouardy.

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×