I am trying to use Jenkins 2.0 with Pipeline Plugin. How can I execute multiple tasks (FreeStyleProject
s) in parallel (via closures).
I tried 2 examples and they both failed. How can I achieve this functionality?
A. Sample Pipeline script;
def taskNames = [
"Test FSP 1",
"Test FSP 2"
]
buildClosures = [:]
for (taskName in taskNames) {
echo "iterating... taskName is: ${taskName}"
def curClosure = {
echo "inside curClosure... taskName is: ${taskName}"
build(taskName)
}
buildClosures.put(taskName, curClosure)
}
parallel(buildClosures)
And this is the output (the last item is built twice, first variable seems to be overridden);
Started by user Cagri Celebi
[Pipeline] echo
iterating... taskName is: Test FSP 1
[Pipeline] echo
iterating... taskName is: Test FSP 2
[Pipeline] Execute in parallel : Start
[Pipeline] [Test FSP 1] parallel { (Branch: Test FSP 1)
[Pipeline] [Test FSP 2] parallel { (Branch: Test FSP 2)
[Pipeline] [Test FSP 1] echo
[Test FSP 1] inside curClosure... taskName is: Test FSP 2
[Pipeline] [Test FSP 1] build (Building Test FSP 2)
[Test FSP 1] Scheduling project: Test FSP 2
[Pipeline] [Test FSP 2] echo
[Test FSP 2] inside curClosure... taskName is: Test FSP 2
[Pipeline] [Test FSP 2] build (Building Test FSP 2)
[Test FSP 2] Scheduling project: Test FSP 2
[Test FSP 1] Starting building: Test FSP 2 #13
[Pipeline] } //parallel
[Pipeline] } //parallel
[Pipeline] Execute in parallel : End
[Pipeline] End of Pipeline
Finished: SUCCESS
B. This one also fails;
subjobIteration = [:]
["Test FSP 1","Test FSP 2"].each{ jobName ->
subjobIteration.put(jobName,{build( jobName )})
}
parallel( subjobIteration )
The output contains only the first item;
Started by user Cagri Celebi
[Pipeline] Execute in parallel : Start
[Pipeline] [Test FSP 1] parallel { (Branch: Test FSP 1)
[Pipeline] [Test FSP 1] build (Building Test FSP 1)
[Test FSP 1] Scheduling project: Test FSP 1
[Test FSP 1] Starting building: Test FSP 1 #3
[Pipeline] } //parallel
[Pipeline] Execute in parallel : End
[Pipeline] End of Pipeline
Finished: SUCCESS