Is it possible to shift or move jobs between two jenkins servers?

+1 vote
I'm trying to shift jenkins jobs from one jenkins server to another, can somebody help me?
Jul 2, 2018 in Jenkins by Hannah
• 14,090 points
626 views

5 answers to this question.

0 votes

You can:

  1. Move a job from one installation of Jenkins to another by simply copying the corresponding job directory.
  2. Make a copy of an existing job by making a clone of a job directory by a different name.
  3. Rename an existing job by renaming a directory. Note that the if you change a job name you will need to change any other job that tries to call the renamed job.

Those operations can be done even when Jenkins is running. For changes like these to take effect, you have to click "reload config" to force Jenkins to reload configuration from the disk.

answered Jul 2, 2018 by Kalgi
• 39,170 points
0 votes

I used Perl to automate such processes using the CLI (go to $jenkins_URL/cli/ and download the Jenkins-cli.jar) (script changed to your scenario)

It is important to make sure that you have all necessary plug-ins installed on your new Jenkins otherwise any migration method won't work...

my $newJobPrefix = "New_Jenkins";
my $jobPrefix = "Old_Jenkins";
my $result = `"$java" -jar old-jenkins-cli.jar -noKeyAuth -s $jenkins_URL list-jobs All`;
@jobList = split("\n", $result);
foreach my $job (@jobList)
{
    # ---- Getting configuration of jobs ----
    print "Getting config for: $job \n";
    my $config = `"$java" -jar $jenkinsJar -noKeyAuth -s $jenkins_URL get-job $job`;

    my $file = "$jobPrefix\\$job.xml";
    unless(open FILE, '>', $file) {die "Unable to open $file";}
    print FILE $config;
    close FILE;

    # ---- Adding Job to new Jenkins ----
    my $result = `"$java" -jar new-jenkins-cli.jar -noKeyAuth -s $New_jenkins_URL create-job $job< $file`;
}
answered Oct 25, 2018 by Kantaben
0 votes

You can also use jenkins cli, I noticed non of these answers had mentioned this method.

  1. First download the Jenkins CLI jar.
  • You can do this from your jenkin's CLI page within your installed Jenkins instance.

jenkins CLI menu

  1. 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

  1. 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

  1. 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.

answered Oct 25, 2018 by Haider
0 votes

Yes ofcourse that's possible, There are three ways of achieving the same:

  1. Move a job from one installation of Jenkins to another by simply copying the corresponding job directory.
  2. Make a copy of an existing job by making a clone of a job directory by a different name.
  3. Rename an existing job by renaming a directory. Note that the if you change a job name you will need to change any other job that tries to call the renamed job.
answered Oct 25, 2018 by krishti
0 votes

There are some Jenkins plugins out there that provide some job export options. There is plugin called job import plugin that is used for importing jobs from other jenkins instances. It might be helpful in your case. Have a look at this documentation for more details.

    answered Oct 25, 2018 by akaash

    Related Questions In Jenkins

    0 votes
    1 answer
    +1 vote
    1 answer
    0 votes
    2 answers

    Is possible for Jenkins to auto start and stop slave nodes?

    Try Jenkins Plugin called as Slave SetupPlugin. This ...READ MORE

    answered Aug 6, 2018 in Jenkins by Nilesh
    • 6,900 points
    719 views
    0 votes
    1 answer

    What are parameterized jobs in jenkins and how to configure it?

    Hey @Hannah, Parameterized jobs/builds are the ones ...READ MORE

    answered Dec 16, 2018 in Jenkins by Kiyara
    616 views
    0 votes
    1 answer
    +13 votes
    2 answers

    Git management technique when there are multiple customers and need multiple customization?

    Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

    answered Mar 26, 2018 in DevOps & Agile by DragonLord999
    • 8,380 points
    112 views
    +1 vote
    3 answers
    +1 vote
    3 answers

    Rename jobs from jenkins file

    Go to the Configure screen and edit the Project name field ...READ MORE

    answered Oct 25, 2018 in Jenkins by Laila
    535 views