RGonza
RGonza

Reputation: 107

Jenkins Buildflow plugin: how to make variable numbers of jobs in parallel?

I have a Job made with BuildFlow, this jobs receives a parameter like job1, job2, job1 job2.

In my DSL I separate the value of the parameter with a split(","), so now I have an array with: ["job1","job2","job1 job2"].

Now i want to make the DSL run a subjob with X builds in parallel, where X is the size of the array, and iterate to get each position of the array as a paramater to pass to the build of the subjob.

Upvotes: 1

Views: 3833

Answers (1)

lixhunter
lixhunter

Reputation: 116

try this within your dsl:

subjob = "yourJobName"
subjobIteration = []

["job1","job2","job1 job2"].each{ parameter ->
  //add the closure to trigger the subjob to the list
  subjobIteration.add({build( subjob, parameter )})
}

parallel( subjobIteration )

This snippet uses the Syntax for Parallel job-executions documented here.

Groovy processes the list subjobIteration by default for the "parallel"-DSL correctly, so no further steps are needed.

Upvotes: 3

Related Questions