Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using failFast with closure map breaks "parallel" step

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)
like image 406
Constantin Avatar asked May 19 '16 20:05

Constantin


2 Answers

map.failFast = true
parallel map
like image 195
Jesse Glick Avatar answered Nov 08 '22 06:11

Jesse Glick


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
])
like image 2
Captain Man Avatar answered Nov 08 '22 08:11

Captain Man