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

+3 votes
I'm trying to shift jenkins jobs from one jenkins server to another, can somebody help me?
Jul 2, 2018 in Jenkins by Hannah
• 18,570 points
44,382 views

7 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
• 52,360 points

Good answer - given it's copied from the wiki, I think I would have just gone with that.
https://wiki.jenkins.io/display/JENKINS/Administering+Jenkins

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
    0 votes

    Job import plugin can be used to copy jobs from other jenkins instance.

    https://plugins.jenkins.io/job-import-plugin/

    answered Jun 24, 2020 by Vinoth
    0 votes

    Hi,

    You can copy Jobs in between your Jenkins server without moving the Job directories. There is one plugin available in Jenkins named the Job import plugin. This plugin helps you to perform your task. You can go through the below link for the plugin.

    https://plugins.jenkins.io/job-import-plugin/

    answered Dec 16, 2020 by MD
    • 95,440 points

    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
    • 7,050 points
    6,288 views
    +1 vote
    1 answer
    +15 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 27, 2018 in DevOps & Agile by DragonLord999
    • 8,450 points
    3,458 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
    4,125 views
    webinar REGISTER FOR FREE WEBINAR X
    REGISTER NOW
    webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP