[英]Can I run parallel actions from a plain Groovy method in my Jenkins pipeline?
My Jenkins pipeline is specified in a declarative way.我的 Jenkins 管道以声明方式指定。 However, in the place I'd like to introduce a parallel step in, I'm forced down into plain Groovy methods:
但是,在我想引入并行步骤的地方,我被迫使用普通的 Groovy 方法:
def call(Map parameters) {
runFirstStep(parameters)
// add second step that runs in parallel to runFirstStep
}
Unexperienced as I am with Groovy and Jenkins, I hoped to make something simple like this work:由于我对 Groovy 和 Jenkins 没有经验,我希望做一些像这样简单的工作:
def call(Map parameters) {
parallel(
'First step': {
runFirstStep(parameters)
},
'Second step': {
runSecondStep(parameters)
}
)
}
However, this seems to mix up declarative and imperative code in an unsuited way and leads to cryptic NullPointerExceptions.但是,这似乎以不合适的方式混合了声明式代码和命令式代码,并导致神秘的 NullPointerExceptions。
Is there another, feasible solution for this?还有其他可行的解决方案吗? Or is overriding the declarative part that surrounds this the only option to squeeze in another parallel step?
还是覆盖围绕它的声明部分是挤进另一个并行步骤的唯一选择?
def call(Map parameters) {
def steps = [:]
steps['First step'] = {
node('master') {
runFirstStep(parameters)
}
}
steps['Second step'] = {
node('master') {
runSecondStep(parameters)
}
}
parallel steps.plus([failFast: true])
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.