Skip to content

Commit b894be2

Browse files
authored
Merge pull request #75 from andrejska/parallelFromList-simplified
As some bugs are fixed on Jenkins side pipeline code can be simplified
2 parents 2367842 + c8fe746 commit b894be2

File tree

2 files changed

+2
-22
lines changed

2 files changed

+2
-22
lines changed

pipeline-examples/parallel-from-list/README.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff 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
179
separate method. I've opted to do so here to show how to return a step
1810
closure from a method.

pipeline-examples/parallel-from-list/parallelFromList.groovy

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,8 @@
66
def 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,

0 commit comments

Comments
 (0)