I'm running the Jenkins Build Flow Plugin with the following script:
def builds = [:]
[1,2].each {
builds[it] = { build("test", parm: ("$it")) }
}
parallel builds
However, whilst the hash (builds[it]) gets populated correctly, the parm is always null. I've also tried the following:
builds[it] = { build("test", parm: $it)) }
builds[it] = { build("test", parm: it)) }
But the it is always null.
Can anyone give me any pointers as to how I can use the $it, or any other variable in the build jobs please.
Seems like you are running into a bug in Build Flow Plugin (I've seen similar issues with Pipeline DSL). No expert, but it seems to be related to groovy closures and scoping of outer variables that are provided by
each
orforeach
constructs. For example (smilar to your example):prints:
while:
will print
as expected. So, use an local variable to store the iteration value.
As per the build flow documentation I believe the syntax should be:
i.e. the
param1
argument name needs to literally readparam
followed by a sequential integer starting with 1.