Currying groovy CPS封闭以并行执行 [英] Currying groovy CPS closure for parallel execution
问题描述
我们在一些工作中动态创建了并行步骤.感谢
We do some dynamic creation of parallel steps in some of our jobs. Thanks to this thread I found how to dynamically create the map with parameters for use in the parallel step.
但是,现在我想重用用于创建这些并行步骤的部分代码.为此,我觉得我需要关闭这些内容.
However now I wanted to reuse parts of the code which is used to create those parallel steps. For this I feel that I would need to curry the closures.
但是,currying似乎无法正常工作.引用闭包内部的循环变量(valueCopy)做正确的事情(如此处所述),但柯里化并没有达到我的预期.
However currying seems not to work correctly. Referencing the loop variable (valueCopy) inside the closure does the right thing (as mentioned here) but currying does not do what I would expect.
我做错什么了吗(是否还不支持),是否有任何解决方法?这可能是詹金斯管道中的错误吗?
Am I doing something wrong, is this just not (yet) supported, are there any workarounds? Is this probably a bug in Jenkins pipeline?
希望任何人都知道为什么这不起作用和/或如何使其起作用.
Hope anybody has a clue why this doesn't work and/or how to get it working.
Jenkins:LTS(2.32.1)&截至2017年1月19日的最新插件更新.
Jenkins: LTS (2.32.1) & latest plugin updates as of 2017/01/19.
升级到管道后:Groovy插件版本2.40现在可以按预期运行.
已执行管道脚本:
def echoSome(val) {
echo val
}
def buildClosures() {
def someList = ["1", "2", "3"]
def closures = [:]
for (value in someList) {
final valueCopy = value
closures[value] = {val ->
echo valueCopy.toString()
echo val.toString()
}.curry(value)
}
closures
}
parallel buildClosures()
输出:
[Pipeline] parallel
[Pipeline] [1] { (Branch: 1)
[Pipeline] [2] { (Branch: 2)
[Pipeline] [3] { (Branch: 3)
[Pipeline] [1] echo
[1] 1
[Pipeline] [1] echo
[1] 3
[Pipeline] [1] }
[Pipeline] [2] echo
[2] 2
[Pipeline] [2] echo
[2] 3
[Pipeline] [2] }
[Pipeline] [3] echo
[3] 3
[Pipeline] [3] echo
[3] 3
[Pipeline] [3] }
[Pipeline] // parallel
[Pipeline] End of Pipeline
Finished: SUCCESS
预期输出:
[Pipeline] parallel
[Pipeline] [1] { (Branch: 1)
[Pipeline] [2] { (Branch: 2)
[Pipeline] [3] { (Branch: 3)
[Pipeline] [1] echo
[1] 1
[Pipeline] [1] echo
[1] 1
[Pipeline] [1] }
[Pipeline] [2] echo
[2] 2
[Pipeline] [2] echo
[2] 2
[Pipeline] [2] }
[Pipeline] [3] echo
[3] 3
[Pipeline] [3] echo
[3] 3
[Pipeline] [3] }
[Pipeline] // parallel
[Pipeline] End of Pipeline
Finished: SUCCESS
推荐答案
发现了最新的管道: Groovy 插件(2.40)至少与Jenkins 2.60.3结合使用(尽管插件首页指出您至少需要Jenkins 2.73.3才有效),所有功能均按预期工作.
Found that with the latest Pipeline: Groovy plugin (2.40) combined with at least Jenkins Version 2.60.3 (works although the plug-ins homepage states that you need at least Jenkins 2.73.3) everything works as expected.
这篇关于Currying groovy CPS封闭以并行执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!