0

I am trying to use Jenkins 2.0 with Pipeline Plugin. How can I execute multiple tasks (FreeStyleProjects) 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
CSchulz
  • 10,882
  • 11
  • 60
  • 114
az3
  • 3,571
  • 31
  • 31
  • 1
    PS: The old examples containing collect and List (i.e. answers on this site) does not work, I think the codebase is changed. – az3 Apr 26 '16 at 13:36
  • 1
    Thanks for the tip StephenKing! It seems like I have the same bug. I'll track it from Jenkins Jira and see if it is solved. – az3 Apr 26 '16 at 14:01

0 Answers0