与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 插件目前,无论嵌套结构如何,都只能按照开始的顺序显示线性的阶段列表.
- 蓝海将显示顶级阶段,以及顶级阶段内的
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
.
JENKINS-27394, if implemented, would display arbitrarily nested stage
s.
这篇关于与Jenkins工作流程/管道并行运行的阶段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!