Skip to content

Instantly share code, notes, and snippets.

@tknerr
Last active February 27, 2017 08:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tknerr/83c6e94f2fed1dc01e4f71e3263fd4b2 to your computer and use it in GitHub Desktop.
Save tknerr/83c6e94f2fed1dc01e4f71e3263fd4b2 to your computer and use it in GitHub Desktop.
Trying to run steps on many slaves in parallel, but when the `doStuff(x)` closure is executed the slave name argument being passed (`x`) is always "slave3"
def onEachSlave(doStuff) {
def doStuffClosures = [:]
for (slave in ['slavelnx1', 'slavelnx2', 'slavelnx3']) {
def s = slave
doStuffClosures[s] = { echo "running on ${s}..."; doStuff(s); echo "...done on ${s}!" }
}
return doStuffClosures
}
parallel(onEachSlave { slave ->
echo "doing stuff on ${slave}..."
})
[Pipeline] parallel
[Pipeline] [slavelnx1] { (Branch: slavelnx1)
[Pipeline] [slavelnx2] { (Branch: slavelnx2)
[Pipeline] [slavelnx3] { (Branch: slavelnx3)
[Pipeline] [slavelnx1] echo
[slavelnx1] running on slavelnx1...
[Pipeline] [slavelnx2] echo
[slavelnx2] running on slavelnx2...
[Pipeline] [slavelnx3] echo
[slavelnx3] running on slavelnx3...
[Pipeline] [slavelnx1] echo
[slavelnx1] doing stuff on slavelnx3
[Pipeline] [slavelnx1] echo
[slavelnx1] ...done on slavelnx1!
[Pipeline] [slavelnx1] }
[Pipeline] [slavelnx2] echo
[slavelnx2] doing stuff on slavelnx3
[Pipeline] [slavelnx2] echo
[slavelnx2] ...done on slavelnx2!
[Pipeline] [slavelnx2] }
[Pipeline] [slavelnx3] echo
[slavelnx3] doing stuff on slavelnx3
[Pipeline] [slavelnx3] echo
[slavelnx3] ...done on slavelnx3!
[Pipeline] [slavelnx3] }
[Pipeline] // parallel
[Pipeline] End of Pipeline
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment