如何在并行执行中启动具有不同参数的相同作业?
我有一个构建作业和一个测试作业参数。
我想在构建作业之后,同时运行具有一个参数的测试作业以及并行执行具有不同参数的相同测试作业。
build job
|
/ \
test job test job
with one params with other params
| |
如何实现这一点以及是否可以在无需编写自己的插件的情况下执行?
谢谢!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
创建测试作业时,将其创建为“构建多配置项目”
配置作业时,选择“配置矩阵”,然后选择“用户定义轴”
您可以使用该轴的名称作为作业中的参数。给定的参数将在不同的作业中同时启动。 (如果有足够的执行者可用)
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)
根据@Soo Wei Tan 的回答,我发现以下内容效果很好。
然后,在 shell 中编写一系列属性文件,触发器插件将处理其余的事情。
您甚至可以以有趣的方式将其与顶层的矩阵式工作结合起来。例如,在用户定义的轴上触发,用网格跟踪所有内容。确实是一个相当灵活的方法,虽然有点隐藏。
Playing off @Soo Wei Tan's answer, I found the following works well.
Then, in a shell, write a series of property files, and the Trigger Plugin will take care of the rest.
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.
我有同样的要求,发现 参数化触发器插件不够灵活,无法将不同的参数并行传递给不同(或相同)的作业。是的,您可以将参数工厂与属性文件一起使用,但这意味着将新的属性文件添加到我的版本控制中只是为了配置 Jenkins。具有配置矩阵的多配置项目似乎也过于复杂。
对我来说更好、更直接的解决方案是 Multijob Plugin< /a>,其中有阶段的概念。多作业可以有多个阶段。阶段按顺序运行,阶段内的作业将同时运行(并行)。
安装 MultiJob 插件后,在创建新的 Jenkins 项目时,选择MultiJob Project。然后您可以创建一个或多个阶段。
阶段中的每个作业都有自己的参数,单击高级... ->添加参数
此外,如果特定作业失败、整个 MultiJob 继续或失败等情况下,配置应该发生的情况也非常容易,请参阅终止阶段:和继续进入下一阶段的条件
当作业的状态为: 设置时。
对我来说,这比参数化触发器插件或多配置项目更直观,并且不需要 Jenkins 之外的任何额外配置。
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.
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
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.
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.
假设您在完成构建作业时知道参数,则可以使用 参数化触发器构建插件可使用不同的参数触发下游作业。
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.
一种选择是使用构建流程插件(https://wiki.jenkins -ci.org/display/JENKINS/Build+Flow+Plugin)可能与 Job DSL 插件(https://wiki.jenkins-ci.org/display/JENKINS/Job+DSL+Plugin)。您可以使用作业 DSL 定义作业步骤,使用不同的命令行参数调用构建,并使用构建流程编排构建。
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.
我的用例略有不同。我们有在开发周期中针对我们的主要构建运行的测试作业。接近周期结束时;我们创建一个候选版本版本并对其运行相同的测试。我们还想继续测试主要版本。
我可以创建具有不同名称的重复作业来处理此问题。但必须有一种更优雅/更简单的方法。
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.
I can create duplicate jobs with just different names to handle this. But there have to be a more elegant/simpler way.
您能否再多说一下为什么需要同时运行测试作业?
我确实使用需要拆分和同时运行的测试,但我使用权重 > 的单个 Jenkins/Hudson 作业。 1(请参阅繁重作业插件)。
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).