git 如何在 Jenkins 中克隆一份工作?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23838259/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 18:06:52  来源:igfitidea点击:

How do I clone a job in Jenkins?

gitjenkinscontinuous-integration

提问by GregH

Jenkinshas the GerritPlugin in place so that when we do check-ins to Gerrit, Jenkinsperforms a build and if it succeeds, then the modification in Gerritis 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.

JenkinsGerrit插件,以便当我们签入到 时GerritJenkins执行构建,如果成功,则Gerrit验证修改。如果构建失败,则不是。我的理解是,这是通过在Jenkins. 我们现在已经创建了一个新分支 ( git),我想我需要克隆指向另一个分支的现有作业,以便发生相同的工作流程并在每次提交时执行构建。有人可以解释我将如何克隆这些工作吗?我似乎没有看到通过 UI 执行此操作的方法,我什至看不到通过 UI 列出作业的方法。

回答by gareth_bowles

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

要复制现有作业,请转到http://your-jenkins/newJob并使用“复制现有作业”选项。输入现有作业的名称 - Jenkins 将验证它是否存在。

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.

Jenkins首页的默认选项卡应该列出所有现有的工作,但也许你的前任删除了该选项卡。您可以创建一个新选项卡,列出来自http://your-jenkins/newView.

回答by prudviraj

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'
  1. 点击“新项目”链接
  2. 为您的工作取一个新名称
  3. 选择单选按钮“复制现有项目”
  4. 提供要克隆的作业名称
  5. 点击“确定”

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

最后,您有了新工作,它反映了您克隆工作的所有功能。

回答by ROMANIA_engineer

Jenkins 2.9

詹金斯 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 Saveif you want to keep the default values.

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

    View jobs

  1. 詹金斯 >新项目

    詹金斯新品

  2. 输入项目名称- 例如“MY_CLONE”

    输入项目名称

  3. 指定源(复制自)作业 >确定

    当您开始键入名称时,将找到现有值。请注意,这是区分大小写的。

    从 OK 复制

  4. 如果要保留默认值,请单击“保存”

  5. 现在这两个工作都在同一位置可用:

    查看职位

回答by ksr

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

New Item> Project Name= abc> 而不是Freestyle job,选择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 ../.

如果您在要从目录中复制的文件夹内,请使用../.

回答by Ulka

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

如果您想在同一个 Jenkins 但在不同的子文件夹中复制,请创建新项目 -> 使用复制自。新作业将被克隆到同一目录中。然后使用移动选项将其移动到所需目录中

回答by Bhushan

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

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

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

在 下Enter an item name,输入所需的新作业名称。然后使用Copy from底部的文本框。输入源作业的作业路径。

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

例如,如果您的源作业在文件夹下src-folder且作业名称为src-job,则必须src-folder/src-job在“复制自”框中输入。

Hope it helps.

希望能帮助到你。

回答by lkisac

You can also use the Copy project linkplugin.

您还可以使用复制项目链接插件。

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

在此处输入图片说明

回答by Rohit Kataria

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

就我而言,我不得不将一份工作从一个 jenkins 实例复制到另一个实例。

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.

因此,首先我查看了旧 Jenkins 的目录结构(作业/目录名称;还注意到了 config.xml),然后查看了新 jenkins 的目录结构,然后在那里创建了一个具有相同名称/作业的目录并复制过来这个新创建的目录下的 config.xml。

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

然后在“管理 Jenkins”下,我点击“从磁盘重新加载配置”。就是这样。

回答by yug

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.

创建一个新项目并转到最后一个您会发现从现有项目复制的选项,只需写下您当前的工作名称,您将拥有该项目的克隆以供使用。

回答by priyanka_rao

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

我无法从子文件夹复制 Jenkins 作业。copy from选项没有显示我正在寻找的建议。不使用建议复制工作名称不起作用。

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.

因此,如果要从外部文件夹创建作业,则需要先在子文件夹中创建作业,然后将其移动到需要放置的不同文件夹中。