Best practice to copy Jenkins jobs from old instance to new one - Different networks - No root access to server - Manual Copying preferred

6,058 views
Skip to first unread message

SamiSam

unread,
Feb 28, 2014, 9:56:42 AM2/28/14
to jenkins...@googlegroups.com
Hi there,

Can someone recommend a way to copy Jenkins jobs from an old server to a new one?  Unfortunatley, I don't have root access to the old server, so copying the directories is not an option.  Using a plugin might not be an option either.  Can this be performed manually?  Any help would be greatly appreciated!

Thanks in advance

Ginga, Dick

unread,
Feb 28, 2014, 10:50:33 AM2/28/14
to jenkins...@googlegroups.com

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

SamiSam

unread,
Feb 28, 2014, 10:58:37 AM2/28/14
to jenkins...@googlegroups.com
Just tried it and keep on receiving:
FAILED - Server returned HTTP response code: 403 for URL: http://*******/job/******//config.xml

this is happening on all the jobs i'm trying to import.

Any ideas?  I don't think I could create an anonymous account (like some have done) and give it admin access..

oh and thanks for the reply and suggestion

Ginga, Dick

unread,
Feb 28, 2014, 10:59:35 AM2/28/14
to jenkins...@googlegroups.com

Sorry, I never used it, just know about it

Kevin Fleming (BLOOMBERG/ 731 LEXIN)

unread,
Feb 28, 2014, 11:00:09 AM2/28/14
to jenkins...@googlegroups.com
If you don't have access to the server, nor access to the API, then there's really no way you can copy the jobs as you can't get their contents.

Slide

unread,
Feb 28, 2014, 11:03:16 AM2/28/14
to Jenkins User Mailing List
The latest version should have a username/password prompt when you go to import, at least it did last time I tried. Are those fields not showing up for you?

slide

SamiSam

unread,
Feb 28, 2014, 11:06:27 AM2/28/14
to jenkins...@googlegroups.com, Kevin Fleming
The plugin displays the credentials window.  I do enter my credentials and can query the remote server which returns a list of jobs under the $VIEWNAME i specify in the URL.  When I do try to import the jobs, that's when I get the 403 error.

Slide

unread,
Feb 28, 2014, 11:15:17 AM2/28/14
to Jenkins User Mailing List
I assume you are logging in with a user that has admin privileges?

SamiSam

unread,
Feb 28, 2014, 11:18:52 AM2/28/14
to jenkins...@googlegroups.com
Good question.. I am not.  and don't think i could get admin rights on here.. I'll check

Patricia Wright

unread,
Feb 28, 2014, 11:30:42 AM2/28/14
to jenkins...@googlegroups.com
Can you use the CLI?

If so, something like this:

java -jar jenkins-cli.jar -s https://oldjenkins.yourdomain.com login 
java -jar jenkins-cli.jar -s https://newjenkins.otherdomain.com login
curl 'https://oldjenkins.yourdomain.com/view/All/api/python?pretty=true' | awk -F\" '/name/{print $4}' > testlist.txt     
for job in `cat testlist.txt` ; do
    java -jar jenkins-cli.jar -s https://oldjenkins.yourdomain.com get-job $job > $job.xml
    java -jar jenkins-cli.jar -s https://newjenkins.otherdomain.com create-job $job < $job.xml
done

If they have locked down the api entirely on the old server, you might be able to do some other html scrape of the all view.

   

Patricia Wright
Sr. MTS, VMware Site Recovery Manager
patr...@vmware.com
5 Cambridge Center, Cambridge MA 02142
617.528.7611 Office


From: "SamiSam" <say...@gmail.com>
To: jenkins...@googlegroups.com
Sent: Friday, February 28, 2014 9:56:42 AM

Subject: Best practice to copy Jenkins jobs from old instance to new one - Different networks - No root access to server - Manual Copying preferred

Hi there,

Can someone recommend a way to copy Jenkins jobs from an old server to a new one?  Unfortunatley, I don't have root access to the old server, so copying the directories is not an option.  Using a plugin might not be an option either.  Can this be performed manually?  Any help would be greatly appreciated!

Thanks in advance


SamiSam

unread,
Feb 28, 2014, 11:45:44 AM2/28/14
to jenkins...@googlegroups.com
Thanks for the suggestion Patricia.. Unfortunately, no access to CLI.. I could have easily copied the directory where the jobs reside in and call it a day.. but that's no an option.  sigh

Patricia Wright

unread,
Feb 28, 2014, 11:50:40 AM2/28/14
to jenkins...@googlegroups.com
Just so I am clear, I'm not referring to the cli of the jenkins server itself.

The CLI I refer to is the remote jenkins command line.

You can download the .jar file from $JENKINS_URL/jnlpJars/jenkins-cli.jar and run it on any machine.




Sent: Friday, February 28, 2014 11:45:44 AM
Subject: Re: Best practice to copy Jenkins jobs from old instance to new one - Different networks - No root access to server - Manual Copying preferred

SamiSam

unread,
Feb 28, 2014, 12:23:28 PM2/28/14
to jenkins...@googlegroups.com, patr...@vmware.com
oh interesting.

I just downloaded jenkins-cli.jar -- a few questions Patricia

the first line: java -jar jenkins-cli.jar -s https://oldjenkins.yourdomain.com login   - will the login be user:password ?

if so, nothing happens on my end.  Should i copy and modify your instructions into a file and execute?  Sorry, I'm not a developer but an Integrator.

Thank you

Patricia Wright

unread,
Feb 28, 2014, 12:57:50 PM2/28/14
to SamiSam, jenkins...@googlegroups.com
You can test to see if this has a hope of working by doing the following:

1) check to see if the CLI works:

     java -jar jenkins-cli.jar -s JENKINS_URL who-am-i --username=YOUR_USERNAME --password=YOUR_PASSWORD

    Replace YOUR_USERNAME and YOUR_PASSWORD as appropriate.

2) If that works and doesn't give you exceptions, you can run something like the following:

    java -jar jenkins-cli.jar -s JENKINS_URL list-jobs --username=YOUR_USERNAME --password=YOUR_PASSWORD
    
    This should give you a list of jobs.    
    Replace "list-jobs" with "get-job SOME_TEST_NAME" and it will spit out a pile of XML at you.
 
3) Doing the transfer

    If all that works, and assuming you have access to create jobs on new jenkins server, and that server has all the needed plugins/prerequisites. 
    You can use the following script:

    Edit the 4 variables at the top as appropriate (this assumes Mac, or some other unix)

    Disclaimer, use at your own risk, of course.   I don't know your environment.
    I did something similar to this in order to migrate from a windows master to a linux master  (I modified the xml files for my own needs). 

#!/bin/bash

OLD_JENKINS_URL=http://oldjenkins.somedomain.com
NEW_JENKINS_URL=http://newjenkins.otherdomain.com
YOUR_USERNAME='replace_here_with_username'
YOUR_PASSWORD='replace_here_with_password'
WORKDIR="/tmp/transfer.$$"
mkdir -p $WORKDIR

java -jar jenkins-cli.jar -s $OLD_JENKINS_URL list-jobs --username "$YOUR_USERNAME" --password "$YOUR_PASSWORD" > testlist.txt


for job in `cat testlist.txt` ; do

   echo Copying job $job
   java -jar jenkins-cli.jar -s $OLD_JENKINS_URL get-job $job --username "$YOUR_USERNAME" --password "$YOUR_PASSWORD" > $WORKDIR/$job.xml
   java -jar jenkins-cli.jar -s $NEW_JENKINS_URL create-job $job --username "$YOUR_USERNAME" --password "$YOUR_PASSWORD" < $WORKDIR/$job.xml
done



Cc: patr...@vmware.com
Sent: Friday, February 28, 2014 12:23:28 PM

SamiSam

unread,
Feb 28, 2014, 2:29:12 PM2/28/14
to jenkins...@googlegroups.com, SamiSam, patr...@vmware.com
Thank you so much for the instructions.  I'm sure this will be a great aid to many users in the community.  Unfortunately, it did not work. I've tried it from 3 different boxes (1 aix, 1 centos and a windows box) and received the same exception:

Exception in thread "main" java.io.EOFException: unexpected stream termination
        at hudson.remoting.ClassicCommandTransport.create(ClassicCommandTransport.java:100)
        at hudson.remoting.Channel.<init>(Channel.java:373)
        at hudson.remoting.Channel.<init>(Channel.java:369)
        at hudson.remoting.Channel.<init>(Channel.java:330)
        at hudson.remoting.Channel.<init>(Channel.java:326)
        at hudson.remoting.Channel.<init>(Channel.java:314)
        at hudson.cli.CLI.connectViaHttp(CLI.java:151)
        at hudson.cli.CLI.<init>(CLI.java:134)
        at hudson.cli.CLI.<init>(CLI.java:107)
        at hudson.cli.CLI._main(CLI.java:395)
        at hudson.cli.CLI.main(CLI.java:330)


Any ideas on how to perform the copy manually then? I guess i'll have to do this job by job at this point.. I only have about 20 jobs to move :)

Christian Willman

unread,
Mar 6, 2014, 4:07:30 AM3/6/14
to jenkins...@googlegroups.com, SamiSam, patr...@vmware.com
Do you still have the administer authorization in the old Jenkins instance? You can write a script like this (psuedocode):

- read a list of job URLs, one URL/line
- for each line:
  - curl http://old-jenkins/job/myjob/config.xml (with basic authorization)
  - curl --data "@config.xml" http://new-jenkins/job/myjob (with basic authorization)

It's a crummy way of doing it, but it's fool-proof, and I'm not sure it's even with the engineering cost for just 20 jobs.
Reply all
Reply to author
Forward
0 new messages