How are updates to global variables synchronized in a Jenkins scripted pipeline?
Here is a simplified code where the global variable in 'mylist'
def mylist = [] // Global Variable
def jobs = [:]
def joblist = [“A”, “B”]
joblist.each {it->
jobs[it] = {
node() {
stage(it) {
// lots of processing ...
mylist.add(it) // Global variable update in jobs running in parallel
}
}
}
}
parallel jobs
I want it to contain either [A,B] or [B,A] if the jobs ran successfully.
Questions:
Is this guaranteed or could there be concurrency issues?
Is the update in the master immediate or does it take place after the job completes?
What if mylist is a complex data structure where different jobs update different parts of the data structure?