File tree Expand file tree Collapse file tree 2 files changed +2
-22
lines changed
pipeline-examples/parallel-from-list Expand file tree Collapse file tree 2 files changed +2
-22
lines changed Original file line number Diff line number Diff line change @@ -5,14 +5,6 @@ a map of steps to be run with the parallel command.
55
66# Caveats
77
8- * Due to limitations in Pipeline - i.e.,
9- [ JENKINS-26481] ( https://issues.jenkins-ci.org/browse/JENKINS-26481 ) -
10- it's not really possible to use Groovy closures or syntax that depends
11- on closures, so you can't do the Groovy standard of using
12- .collectEntries on a list and generating the steps as values for the
13- resulting entries. You also can't use the standard Java syntax for For
14- loops - i.e., "for (String s: strings)" - and instead have to use old
15- school counter-based for loops.
168* There is no need for the generation of the step itself to be in a
179separate method. I've opted to do so here to show how to return a step
1810closure from a method.
Original file line number Diff line number Diff line change 66def stringsToEcho = [" a" , " b" , " c" , " d" ]
77
88// The map we'll store the parallel steps in before executing them.
9- def stepsForParallel = [:]
10-
11- // The standard 'for (String s: stringsToEcho)' syntax also doesn't work, so we
12- // need to use old school 'for (int i = 0...)' style for loops.
13- for (int i = 0 ; i < stringsToEcho. size(); i++ ) {
14- // Get the actual string here.
15- def s = stringsToEcho. get(i)
16-
17- // Transform that into a step and add the step to the map as the value, with
18- // a name for the parallel step as the key. Here, we'll just use something
19- // like "echoing (string)"
20- def stepName = " echoing ${ s} "
21-
22- stepsForParallel[stepName] = transformIntoStep(s)
9+ def stepsForParallel = stringsToEcho. collectEntries {
10+ [" echoing ${ it} " : transformIntoStep(it)]
2311}
2412
2513// Actually run the steps in parallel - parallel takes a map as an argument,
You can’t perform that action at this time.
0 commit comments