与 Jenkins 工作流/管道并行运行阶段 [英] Running stages in parallel with Jenkins workflow / pipeline
问题描述
请注意:该问题基于旧的、现在称为脚本化"管道格式.使用声明式管道"时,并行块可以嵌套在阶段块内(参见 使用声明式流水线 1.2 的并行阶段).
Please note: the question is based on the old, now called "scripted" pipeline format. When using "declarative pipelines", parallel blocks can be nested inside of stage blocks (see Parallel stages with Declarative Pipeline 1.2).
我想知道并行步骤应该如何与 Jenkins 工作流/管道插件一起工作,尤其是.如何将它们与构建阶段混合.我知道一般模式:
I'm wondering how parallel steps are supposed to work with Jenkins workflow/pipeline plugin, esp. how to mix them with build stages. I know about the general pattern:
parallel(firstTask: {
// Do some stuff
}, secondTask: {
// Do some other stuff in parallel
})
但是,我想并行运行几个阶段(在同一个节点上,它有多个执行器),所以我尝试添加这样的阶段:
However, I'd like to run couple of stages in parallel (on the same node, which has multiple executors), so I tried to add stages like this:
stage 'A'
// Do some preparation stuff
parallel(firstTask: {
stage 'B1'
// Do some stuff
}, secondTask: {
stage 'B2'
// Do some other stuff in parallel
})
stage 'C'
// Finalizing stuff
这不能按预期工作.做东西"任务是并行执行的,但并行阶段会立即结束,并且不会合并它们应该包含的东西.因此,舞台视图不会显示正确的结果,也不会链接日志.
This does not work as expected. The "do stuff" tasks are executed in parallel, but the parallel stages end immediately and do not incorporate the stuff they should contain. As a consequence, the Stage View does not show the correct result and also does not link the logs.
我可以并行构建不同的阶段,还是并行"步骤仅用于单个阶段?
Can I build different stages in parallel, or is the "parallel" step only meant to be used within a single stage?
推荐答案
您不能将已弃用的非块作用域 stage
(如原始问题中的)放在 parallel中代码>.
You may not place the deprecated non-block-scoped stage
(as in the original question) inside parallel
.
从 JENKINS-26107 开始,stage
采用块参数.你可以把 parallel
放在 stage
或 stage
里面 parallel
或 stage
里面 >stage
等.但是,构建的可视化不能保证支持所有嵌套;特别是
As of JENKINS-26107, stage
takes a block argument. You may put parallel
inside stage
or stage
inside parallel
or stage
inside stage
etc. However visualizations of the build are not guaranteed to support all nestings; in particular
- 内置的流水线步骤(一个树表"列出了构建运行的每个步骤)显示了任意的
stage
嵌套. - Pipeline Stage View 插件目前只显示阶段的线性列表,按照它们开始的顺序,不管嵌套结构如何.
- Blue Ocean 将显示顶级阶段,以及顶级内的
parallel
分支阶段,但目前没有更多.
- The built-in Pipeline Steps (a "tree table" listing every step run by the build) shows arbitrary
stage
nesting. - The Pipeline Stage View plugin will currently only display a linear list of stages, in the order they started, regardless of nesting structure.
- Blue Ocean will display top-level stages, plus
parallel
branches inside a top-level stage, but currently no more.
JENKINS-27394,如果实施,将显示任意嵌套的stage
s.
JENKINS-27394, if implemented, would display arbitrarily nested stage
s.
这篇关于与 Jenkins 工作流/管道并行运行阶段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!