问题
Not sure if it's my limited knowledge of Groovy or a quirk in Pipeline parallel
step. I can't make it accept failFast
if I use map instead of passing each closure individually:
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.
The exception with failFast
is:
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)
回答1:
map.failFast = true
parallel map
回答2:
It helps a little if you add the optional syntax in. The second option is passing a new Map
while the third option is passing your original Map
and an additional named parameter. Honestly I'm not sure what it thinks is going on.
parallel(map)
parallel([
spam: map['spam'],
eggs: map['eggs'],
failFast: true
])
parallel map, failFast: true
In any case I think the simplest thing would be this:
def map = [
spam: {
node {
echo 'spam'
}
},
eggs: {
node {
echo 'eggs'
}
},
failFast: true
]
parallel map
or...
parallel ([
spam: {
node {
echo 'spam'
}
},
eggs: {
node {
echo 'eggs'
}
},
failFast: true
])
回答3:
In addition to Jesse Glick's answer.
Even if you use a for loop to create a parallel stages you can use the same code -
map.failFast = true
parallel map
来源:https://stackoverflow.com/questions/37333796/using-failfast-with-closure-map-breaks-parallel-step