一尘不染

Currying groovy CPS封闭以并行执行

jenkins

我们在某些工作中动态创建并行步骤。感谢这个线程,我找到了如何动态创建带有并行步骤中使用的参数的地图。

但是,现在我想重用用于创建这些并行步骤的部分代码。为此,我觉得我需要关闭这些内容。

但是,currying似乎无法正常工作。引用闭包内部的循环变量(valueCopy)做正确的事,但是currying并没有达到我的期望。

我做错什么了吗?是否还不支持?有没有解决方法?这可能是詹金斯管道中的错误吗?

希望任何人都有线索,为什么这不起作用和/或如何使其起作用。

Jenkins:截至2017/01/19的LTS(2.32.1)和最新的插件更新。

解:

升级到Pipeline之后:Groovy插件版本2.40 eveything现在可以按预期工作。

执行管道脚本:

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

阅读 350

收藏
2020-07-25

共1个答案

一尘不染

发现使用最新的Pipeline:Groovy插件(2.40)至少与Jenkins版本2.60.3结合使用(尽管插件主页指出您至少需要Jenkins 2.73.3才有效),所有功能均按预期工作。

2020-07-25