Shashi Ranjan
Shashi Ranjan

Reputation: 1561

Way to clone a job from one jenkins to another

I have two Jenkins, both are master. Both have 5 salve Jenkins each. I have one job on first jenkins that needs to be cloned for each job. I can clone the job on first jenkins and its slave but not on second master jenkins. Is there a way to clone a job from one jenkins to another?

I have one more question can I archive the job at some defined location other than master jenkins, May be on slave?

Upvotes: 0

Views: 2864

Answers (2)

sti
sti

Reputation: 11075

I assume you have a job called "JOB" on "Jenkins1" and you want to copy it to "Jenkins2":

curl JENKINS1_URL/job/JOB/config.xml | java -jar jenkins-cli.war -s JENKINS2_URL create-job

You might need to add username and password if you have turned on security in Jenkins. The jenkins-cli.war is available from your $JENKINS_URL/cli.

Ideally you should make sure you have the same plugins installed on both Jenkins1 and Jenkins2. More similar you can make the two Jenkins masters, the fewer problems you will have importing the the job.

Upvotes: 1

Slav
Slav

Reputation: 27485

For the second part of your question: slaves don't store any Jenkins configuration. All configuration is done on Master. There is a lot of backup plugins, some backup the whole Jenkins, some backup just job configuration, some backup individual jobs, export them to files, or even store/track changes from SCM such as SVN.

So "archiving job configuration to slave" simply makes no sense. But at the end of the day, a job configuration is simply an .xml file, and you can take that file and copy it anywhere you want.

As for the first part of the question, it's unclear what you want. Do you want to clone a job automatically (as part of another job's process), programmatically (through some script) or manually (through the UI, other means)?

Edit:
Go to your JENKINS_HOME directory on the server filesystem, navigate to the jobs folder, then select the specific job folder that you want.

  • Copy the config.xml to another server, this will create the same job with the same configuration (make sure your plugins are same)
  • Copy the whole job_name folder if you want to preserve history, builds, artifacts, etc

Upvotes: 0

Related Questions