使用带有闭包映射的failFast中断“并行”步骤

时间:2016-05-19 20:52:48

标签: jenkins groovy jenkins-workflow jenkins-pipeline

不确定这是我对Groovy的有限了解还是管道parallel步骤中的怪癖。如果我使用map而不是单独传递每个闭包,我无法接受failFast

def map = [:]
map['spam'] = {
    node {
        echo 'spam'
    }
}
map['eggs'] = {
    node {
        echo 'eggs'
    }
}
parallel map // Works.
parallel spam: map['spam'], eggs: map['eggs'], failFast: true // Works.
parallel map, failFast: true // Fails with exception.

failFast的例外是:

java.lang.IllegalArgumentException: Expected named arguments but got [{failFast=true}, {spam=org.jenkinsci.plugins.workflow.cps.CpsClosure2@51a382ad, eggs=org.jenkinsci.plugins.workflow.cps.CpsClosure2@718cb50d}]
    at org.jenkinsci.plugins.workflow.cps.DSL.parseArgs(DSL.java:276)
    at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:111)

3 个答案:

答案 0 :(得分:23)

map.failFast = true
parallel map

答案 1 :(得分:1)

如果添加可选语法,它会有所帮助。第二个选项是传递新的Map,而第三个选项传递原始Map和另一个命名参数。老实说,我不确定它的想法是什么。

parallel(map)
parallel([
    spam: map['spam'],
    eggs: map['eggs'],
    failFast: true
])
parallel map, failFast: true

无论如何,我认为最简单的事情就是:

def map = [
    spam: {
        node {
            echo 'spam'
        }
    },
    eggs: {
        node {
            echo 'eggs'
        }
    },
    failFast: true
]
parallel map

...或

parallel ([
    spam: {
        node {
            echo 'spam'
        }
    },
    eggs: {
        node {
            echo 'eggs'
        }
    },
    failFast: true
])

答案 2 :(得分:0)

除了Jesse Glick的answer

即使使用for循环创建并行阶段,也可以使用相同的代码-

map.failFast = true
parallel map