Updates to global variables from different nodes in a scripted Jenkins pipeline

Viewed 300

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:

  1. Is this guaranteed or could there be concurrency issues?

  2. Is the update in the master immediate or does it take place after the job completes?

  3. What if mylist is a complex data structure where different jobs update different parts of the data structure?

0 Answers
Related