如何在并行执行中以不同的参数启动相同的作业?

时间:2021-12-22 06:59:19

I have a build job and a test job parameters.

我有一个构建作业和一个测试作业参数。

I want to be after the build job, simultaneously run test job with one parameter and the same test job with different parameters in parallel execution.

我希望在构建作业之后,同时运行一个参数的测试作业,以及在并行执行中具有不同参数的相同测试作业。

                build job  
                   |  
                  / \  
         test job    test job
   with one params    with other params
            |             |

How to accomplish this and whether it is possible to perform without having to write your own plugin?

如何做到这一点,以及是否可以不用编写自己的插件就可以执行?

Thanks!

谢谢!

7 个解决方案

#1


20  

When you create your test job, create it as a "Build multi-configuration project" While configuring the job select "Configuration Matrix" then "User-defined axis"

当您创建测试作业时,将其创建为“构建多配置项目”,同时配置作业选择“配置矩阵”,然后“用户定义轴”

You can use the name of this axis as a parameter in your job. the given parameters will be started simultaneous in different jobs. (if enough executors are available)

您可以在作业中使用此轴的名称作为参数。给定的参数将在不同的作业中同时启动。(如果有足够的执行人)

#2


2  

Playing off @Soo Wei Tan's answer, I found the following works well.

通过对@Soo Wei Tan的回答,我发现下面的作品不错。

  • Parameterized Trigger Plugin
  • 参数化引发插件
  • Choose "Parameter Factory"
  • 选择“参数工厂”
  • Choose "For every property file, invoke one build"
  • 选择“对于每个属性文件,调用一个构建”

Then, in a shell, write a series of property files, and the Trigger Plugin will take care of the rest.

然后,在shell中,编写一系列属性文件,触发器插件将负责其余部分。

You can even combine this with a matrix style job at the top level in interesting ways. For example, triggering on the user-defined axis, keeping track of it all with a grid. Really quite a flexible approach, if a bit hidden.

你甚至可以用有趣的方式把它和矩阵风格的工作结合在一起。例如,在用户定义的轴上触发,并将其与网格保持一致。这是一种非常灵活的方法,如果有点隐蔽的话。

#3


1  

Assuming you know the parameters when you are finishing your build job, you can use the Parameterized Trigger Build plugin to fire both downstream jobs with different parameters.

假设您在完成构建作业时知道了参数,可以使用参数化触发器构建插件以不同的参数触发下游作业。

#4


1  

I had the same requirement, and found that Parameterized Trigger Plugin was not flexible enough for passing different parameters to different (or the same) jobs in parallel. Yes you can use a Parameter Factory with property files, but that would mean adding new property files to my version control solely for the purpose of configuring Jenkins. A Multi-Configuration project with a configuration matrix also seemed overcomplicated.

我有相同的要求,发现参数化的触发器插件没有足够的灵活性,可以将不同的参数传递给不同的(或相同的)作业。是的,您可以使用带有属性文件的参数工厂,但是这意味着只为了配置Jenkins而将新的属性文件添加到我的版本控制中。配置矩阵的多配置项目也显得过于复杂。

The better and more straightforward solution for me was the Multijob Plugin, which has the concept of Phases. A MultiJob can have multiple phases. Phases run sequentially and jobs within a phase will run concurrently (in parallel).

对我来说,更好更直接的解决方案是多任务插件,它具有阶段的概念。多任务可以有多个阶段。阶段依次运行,阶段中的作业将并发地运行(并行地)。

After installing the MultiJob plugin, when creating a new Jenkins item, select MultiJob Project. You can then create one or more phases. Each job within a phase has it own parameters, click Advanced... -> Add Parameters

在安装多任务插件后,当创建一个新的Jenkins项目时,选择MultiJob项目。然后可以创建一个或多个阶段。每个阶段的工作都有它自己的参数,点击Advanced…- >添加参数

Also it is very easy to configure what should happen if a particular job fails, should the entire MultiJob continue or fail etc, see the Kill the phase on: and Continuation condition to next phase when jobs' statuses are: settings.

另外,如果某个特定的工作失败了,如果整个多任务继续或失败,那么就很容易配置应该发生的事情,看到“杀死”阶段:以及当jobs的状态是:设置时,下一个阶段的延续条件。

For me this was much more intuitive to use than the Parameterized Trigger Plugin or a Mult-Configuration project, and did not require any extra configuration outside of Jenkins.

对我来说,这比参数化的触发器插件或mult配置项目更直观,而且不需要在Jenkins之外添加任何额外的配置。

#5


0  

One option would be to use Build Flow plugin (https://wiki.jenkins-ci.org/display/JENKINS/Build+Flow+Plugin) potentially together with Job DSL plugin (https://wiki.jenkins-ci.org/display/JENKINS/Job+DSL+Plugin). You can use Job DSL to define job steps that invoke your build with different command line arguments and orchestrate the build with Build Flow.

一种选择是使用Build Flow插件(https://wiki.jenkins-ci.org/display/JENKINS/Build+Flow+ plugin)与Job DSL插件(https://wiki.jenkins-ci.org/display/JENKINS/Job+DSL+ plugin)一起使用。您可以使用Job DSL来定义用不同的命令行参数调用构建的作业步骤,并使用构建流编排构建。

#6


0  

I have a slightly different use case. We have test jobs that run against our main build during the development cycle. Toward the end of the cycle; we create a release candidate build and run the same tests against that. We want to also continue testing the main build.

我有一个稍微不同的用例。在开发周期中,我们有针对主要构建的测试作业。在周期的末尾;我们创建一个发布候选版本,并对其运行相同的测试。我们还希望继续测试主构建。

               Main Build     Release Build
                         \   /
                           |
                       same set of tests

I can create duplicate jobs with just different names to handle this. But there have to be a more elegant/simpler way.

我可以创建重复的作业,用不同的名称来处理这个。但必须有一种更优雅/更简单的方式。

#7


-2  

Could you please say a bit more why do you need your test jobs to run concurrently?

请您再说一遍,您为什么需要您的测试作业并发运行?

I do use test that need to split and run simultaneously, but I use a single Jenkins/Hudson job that has a weight > 1 (see Heavy Job Plugin).

我确实使用了需要同时拆分和运行的测试,但是我使用的是一个单独的Jenkins/Hudson任务,它有一个重量级的> 1(参见Heavy job Plugin)。

#1


20  

When you create your test job, create it as a "Build multi-configuration project" While configuring the job select "Configuration Matrix" then "User-defined axis"

当您创建测试作业时,将其创建为“构建多配置项目”,同时配置作业选择“配置矩阵”,然后“用户定义轴”

You can use the name of this axis as a parameter in your job. the given parameters will be started simultaneous in different jobs. (if enough executors are available)

您可以在作业中使用此轴的名称作为参数。给定的参数将在不同的作业中同时启动。(如果有足够的执行人)

#2


2  

Playing off @Soo Wei Tan's answer, I found the following works well.

通过对@Soo Wei Tan的回答,我发现下面的作品不错。

  • Parameterized Trigger Plugin
  • 参数化引发插件
  • Choose "Parameter Factory"
  • 选择“参数工厂”
  • Choose "For every property file, invoke one build"
  • 选择“对于每个属性文件,调用一个构建”

Then, in a shell, write a series of property files, and the Trigger Plugin will take care of the rest.

然后,在shell中,编写一系列属性文件,触发器插件将负责其余部分。

You can even combine this with a matrix style job at the top level in interesting ways. For example, triggering on the user-defined axis, keeping track of it all with a grid. Really quite a flexible approach, if a bit hidden.

你甚至可以用有趣的方式把它和矩阵风格的工作结合在一起。例如,在用户定义的轴上触发,并将其与网格保持一致。这是一种非常灵活的方法,如果有点隐蔽的话。

#3


1  

Assuming you know the parameters when you are finishing your build job, you can use the Parameterized Trigger Build plugin to fire both downstream jobs with different parameters.

假设您在完成构建作业时知道了参数,可以使用参数化触发器构建插件以不同的参数触发下游作业。

#4


1  

I had the same requirement, and found that Parameterized Trigger Plugin was not flexible enough for passing different parameters to different (or the same) jobs in parallel. Yes you can use a Parameter Factory with property files, but that would mean adding new property files to my version control solely for the purpose of configuring Jenkins. A Multi-Configuration project with a configuration matrix also seemed overcomplicated.

我有相同的要求,发现参数化的触发器插件没有足够的灵活性,可以将不同的参数传递给不同的(或相同的)作业。是的,您可以使用带有属性文件的参数工厂,但是这意味着只为了配置Jenkins而将新的属性文件添加到我的版本控制中。配置矩阵的多配置项目也显得过于复杂。

The better and more straightforward solution for me was the Multijob Plugin, which has the concept of Phases. A MultiJob can have multiple phases. Phases run sequentially and jobs within a phase will run concurrently (in parallel).

对我来说,更好更直接的解决方案是多任务插件,它具有阶段的概念。多任务可以有多个阶段。阶段依次运行,阶段中的作业将并发地运行(并行地)。

After installing the MultiJob plugin, when creating a new Jenkins item, select MultiJob Project. You can then create one or more phases. Each job within a phase has it own parameters, click Advanced... -> Add Parameters

在安装多任务插件后,当创建一个新的Jenkins项目时,选择MultiJob项目。然后可以创建一个或多个阶段。每个阶段的工作都有它自己的参数,点击Advanced…- >添加参数

Also it is very easy to configure what should happen if a particular job fails, should the entire MultiJob continue or fail etc, see the Kill the phase on: and Continuation condition to next phase when jobs' statuses are: settings.

另外,如果某个特定的工作失败了,如果整个多任务继续或失败,那么就很容易配置应该发生的事情,看到“杀死”阶段:以及当jobs的状态是:设置时,下一个阶段的延续条件。

For me this was much more intuitive to use than the Parameterized Trigger Plugin or a Mult-Configuration project, and did not require any extra configuration outside of Jenkins.

对我来说,这比参数化的触发器插件或mult配置项目更直观,而且不需要在Jenkins之外添加任何额外的配置。

#5


0  

One option would be to use Build Flow plugin (https://wiki.jenkins-ci.org/display/JENKINS/Build+Flow+Plugin) potentially together with Job DSL plugin (https://wiki.jenkins-ci.org/display/JENKINS/Job+DSL+Plugin). You can use Job DSL to define job steps that invoke your build with different command line arguments and orchestrate the build with Build Flow.

一种选择是使用Build Flow插件(https://wiki.jenkins-ci.org/display/JENKINS/Build+Flow+ plugin)与Job DSL插件(https://wiki.jenkins-ci.org/display/JENKINS/Job+DSL+ plugin)一起使用。您可以使用Job DSL来定义用不同的命令行参数调用构建的作业步骤,并使用构建流编排构建。

#6


0  

I have a slightly different use case. We have test jobs that run against our main build during the development cycle. Toward the end of the cycle; we create a release candidate build and run the same tests against that. We want to also continue testing the main build.

我有一个稍微不同的用例。在开发周期中,我们有针对主要构建的测试作业。在周期的末尾;我们创建一个发布候选版本,并对其运行相同的测试。我们还希望继续测试主构建。

               Main Build     Release Build
                         \   /
                           |
                       same set of tests

I can create duplicate jobs with just different names to handle this. But there have to be a more elegant/simpler way.

我可以创建重复的作业,用不同的名称来处理这个。但必须有一种更优雅/更简单的方式。

#7


-2  

Could you please say a bit more why do you need your test jobs to run concurrently?

请您再说一遍,您为什么需要您的测试作业并发运行?

I do use test that need to split and run simultaneously, but I use a single Jenkins/Hudson job that has a weight > 1 (see Heavy Job Plugin).

我确实使用了需要同时拆分和运行的测试,但是我使用的是一个单独的Jenkins/Hudson任务,它有一个重量级的> 1(参见Heavy job Plugin)。