259

Jenkins has the Gerrit Plugin in place so that when we do check-ins to Gerrit, Jenkins performs a build and if it succeeds, then the modification in Gerrit is verified. If the build fails then it is not. My understanding is that this is accomplished through jobs set up in Jenkins. We have now created a new branch (git) and I guess I need to clone the existing jobs pointing to the other branch so that this same workflow occurs and builds are performed on every commit. Can somebody explain how I would clone these jobs? I don't seem to see a way to do it through the UI nor can I even see a way to list the jobs out through the UI.

Guy Avraham
  • 2,830
  • 2
  • 31
  • 43
GregH
  • 10,640
  • 21
  • 63
  • 96
  • 9
    You should be able to "Copy Existing Job" as one of the options on the New Job page. See https://stackoverflow.com/questions/3133537/how-can-i-copy-paste-or-duplicate-an-existing-project – nofinator May 23 '14 at 21:05

12 Answers12

199

To copy an existing job, go to http://your-jenkins/newJob and use the "Copy existing job" option. Enter the name of the existing job - Jenkins will verify whether it exists.

The default tab on the front page of Jenkins should list all existing jobs, but maybe your predecessor deleted the tab. You can create a new tab listing all jobs from http://your-jenkins/newView.

gareth_bowles
  • 19,908
  • 5
  • 52
  • 79
  • 3
    beware, that while copying existing job, you need to provide the name (not encoded as in url while accessing the job), so if the job name has spaces, they will be preserved. Shortly, put only original *name* of the job, nothing else. – Yauhen Jun 21 '18 at 14:39
  • With the ez-template plugin installed "Copy existing job" applied to a template or to a job using a template creates a new job dependent on the template. If you actually want an independent copy you can then delete the `Use another job as a template` configuration. – user598656 Jan 02 '19 at 15:59
157

You can clone a job:

  1. Click on 'New Item' link
  2. Give a new name for your job
  3. Select radio button 'Copy existing Item'
  4. Give the job name that you want to clone
  5. Click 'OK'

Finally, you have your new job, which reflects all features of your cloned one.

Brad Koch
  • 16,415
  • 18
  • 102
  • 128
prudviraj
  • 3,334
  • 2
  • 12
  • 21
126

Jenkins 2.9

  1. Jenkins > New Item

    Jenkins New Item

  2. Enter an item name - E.g. "MY_CLONE"

    Enter an item name

  3. Specify the source (Copy from) job > OK

    When you start typing the name, the existing values will be found. Notice that this is case sensitive.

    Copy from OK

  4. Click on Save if you want to keep the default values.

  5. Now both jobs are available in the same location:

    View jobs

Elrond_EGLDer
  • 47,430
  • 25
  • 189
  • 180
  • 4
    Pictures are worth a thousand words. Couldn't find the little dropdown for the life of me. Mulțumiri – michaelok Apr 19 '18 at 21:01
45

New Item>Project Name = abc > Instead of Freestyle job, select Copy from job name of already existing jobs

If you are inside the folder that you want to copy out of the directory then use ../.

Chaitanya Bapat
  • 1,328
  • 2
  • 17
  • 37
ksr
  • 453
  • 4
  • 4
16

if you want to copy in same Jenkins but in different subfolders, create new item -> use copy from. new Job will be cloned in same directory. Then use move option to move it in desired directory

Ulka
  • 161
  • 1
  • 2
12

In my case, I had to copy over a job from one jenkins instance to another.

So first I looked under the directory structure of the old Jenkins (the job/directory name; also noted the config.xml) and then under the directory structure of the new jenkins where I then created a directory with same name/job and copied over the config.xml under this newly created dir.

Then under, "Manage Jenkins", I hit "Reload Configuration from Disk". Thats it.

Rohit Kataria
  • 161
  • 1
  • 4
  • thanks for the "Reload Configuration from Disk" tip! – Aliza Feb 14 '16 at 07:09
  • 1
    Yeah, doing like this when I have to bulk copy several items, before "Reloading from Disk" you can also do some required manual magic in CLI such as search/replace some parameters, pieces of text, etc in **config.xml**. Note that the name of the directory where **config.xml** is located is the name of your Job (thus, if unlike Rohit you need to create a new Job, just give it a different name). – RAM237 Feb 22 '18 at 12:06
  • In my opinion, when you have several levels of folders with many jobs inside, this is the best option. – cabreracanal May 22 '18 at 10:00
12

All above answers are good. But if you have created "folders" for your jobs, things are slightly different.

Click on the folder under which you want to create a new job. Then click "New Item" on the left menu. Now your "new job" URL will look like this (assuming you are creating the new job under "my-folder"):

http://my-jenkins:8080/job/my-folder/newJob

Under Enter an item name, enter your desired new job name. Then use the Copy from text box at the bottom. Enter job path of he source job.

E.g. If your source job is under folder src-folder and name of the job is src-job, you will have to enter src-folder/src-job in "Copy from" box.

Hope it helps.

Bhushan
  • 16,055
  • 24
  • 96
  • 132
  • I am still trying to find a way to copy jobs cross folder structures: Jenkins add the literal "job" for each new item that is a folder, e.g. I have a job at **http://localhost:8080/job/x/job/y/job_1**, where x and y are folders. job_1 is the real job. How can I copy this job to **http://localhost:8080/job/x/job/z/job_1**? I tried all reference to the source job with no luck. – Heinz Sep 07 '17 at 17:37
  • 1
    Go to `localhost:8080/job/x/job/y/job_1`. On that page, you should see `Full project name`. Try using that when you specify the source. – Bhushan Sep 07 '17 at 17:47
  • If you have 2 folders `folder1` and `folder2` at the same level and you want to copy `folder1\job1` to `folder2\job1`, you can create a new item into folder `folder2` and then use `..` to go back in the folder structure and copy `../folder1/job1`. – DRz Aug 15 '18 at 13:45
10

You can also use the Copy project link plugin.

This will add a link on the left side panel of your project:

enter image description here

Following screen will ask for the new Job name:

enter image description here

lkisac
  • 1,627
  • 21
  • 26
3

Create a new Item and go to the last you'll find option to copy from existing, just write your current job name and you will have clone of that project to work with.

yug
  • 572
  • 1
  • 7
  • 24
1

I was not able to copy Jenkins job from subfolder. copy from option did not show the suggestion which i was looking for.Without using suggestion copying the job name didn't work.

So if you want to create a job from outer folder, you need to first create the job in subfolder and then move it in different folder where you need to place it.

priyanka_rao
  • 405
  • 1
  • 4
  • 17
0

You could use Jobcopy Builder plugin

Sophist
  • 11
  • 1
  • 1
0

All the answers here are super helpful but miss one very weird bug about Jenkins. After you have edited the new job configurations, sometimes if your zoom level is too high, you may not see the save or apply button option. The button is present on the page and hidden by your zoom level, you have to zoom out until you see the button at the bottom left of your page.

Strange, I know!

avp
  • 1,888
  • 23
  • 27