title: With Jenkins Pipeline scripts, is it safe to access a global variable from a parallel step?
body: <p>When writing Jenkins Pipeline scripts, is it safe to access variables from parallel steps? The documentation isn't clear on this.</p>
  
  <p>For example, this pipeline code modifies a common counter and queue from parallel branches:</p>
  
  <pre><code>def donecount = 0;
  def work = [6,5,4,3,2,1,0]
  
  def branches = [:]
  for (int i = 0; i &lt; 3; i++) {
  
      branches["worker-${i}"] = {
  
          while (true) {
              def item = null
              try {
                  item = work.remove(0)
              } catch (java.lang.IndexOutOfBoundsException e) {
                  break
              }
  
              echo "Working for ${item} seconds"
              sleep time:item
              donecount += 1
          }
  
      }
  
  }
  branches.failFast = true
  parallel branches
  
  echo "Completed ${donecount} tasks"
  </code></pre>