So, just in case anyone else has this problem. Variable scope is a thing.
Adding a 'def' fixes everything.
for (int i = 0; i < list.size(); i++) {
def thing = list.get(i)
print thing
branches[thing] = {
node {
print thing
}
}
parallel branches
On Thursday, March 17, 2016 at 10:57:01 AM UTC-4, John Thompson wrote:
>
>
> I have code like the following: (obviously more complicated, but this
> shows the problem)
>
> for (int i = 0; i < list.size(); i++) {
> thing = list.get(i)
> print thing
> branches[thing] = {
> node {
> print thing
> }
> }
> parallel branches
>
> As it's building the branches, it prints out each thing in the list in
> order as I would expect. When it actually *executes* the branches, it
> prints the last thing in the list for as many items there are in the list.
> From what I understand, that's because it's executing the value of the
> external variable at the time the job is run, rather than what it was at
> the time the branch was built. Which I believe is the correct behavior, so
> I'm probably approaching this the wrong way.
>
> What would be the correct way to run several parallel tasks on different
> items in a list? Is there a way to built the code block for each branch so
> it has the *value* of the variable when I'm building it rather than the
> *variable itself*?
>
--
You received this message because you are subscribed to the Google Groups
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/jenkinsci-users/be38156c-7a25-470c-ada7-48204b5dc0c6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.