title: The jenkins parallel at the same time using pop() to a global list, lead to Cannot pop() an empty List?
body: <p>need help
  The problem of multiple threads sharing global variables in Groovy or Jenkins DSL</p>
  <p>I have tried all sort of ways but nothing seems to be working. Here is my jenkinsfile.</p>
  <pre><code>def fill_list() {
      def test_list = []
      for ( int i = 0; i &lt; 160; i++ ) {
          test_list.add(i)
      }
      return test_list
  }
  
  pipeline {
      agent any
  
      stages {
          stage('Init Workspace') {
              steps {
                  script {
                      test_list_generate = fill_list()
                  //  println(test_list_generate)
                     }
              }
          }
          stage('Example Stage 2') {
              parallel {
                      stage('stream_1') {
                      agent { label 'infraTest' }
                          steps {
                              script {
                                  while (test_list_generate.size() != 0) {
                                      sleep 4
                                      println(test_list_generate.size())
                                      println(test_list_generate.pop())
                                      println(&quot;node executor num: ${env.EXECUTOR_NUMBER}&quot;)
                                  }
                              }
                          }
                      }
                      stage('stream_2') {
                      agent { label 'infraTest' }
                          steps {
                              script {
                                  while (test_list_generate.size() != 0) {
                                      sleep 3
                                      println(test_list_generate.size())
                                      println(test_list_generate.pop())
                                      println(&quot;node executor num: ${env.EXECUTOR_NUMBER}&quot;)
                                  }
                              }
                          }
                      }
              }
          }
      }
  }
  
  </code></pre>
  <p>How can I solve these problems?Please change the label in the code to your local valid label</p>
  <p>2021-05-11 23:04:47.221  Also:   java.util.NoSuchElementException: Cannot pop() an empty List
  2021-05-11 23:04:47.221         at org.codehaus.groovy.runtime.DefaultGroovyMethods.pop(DefaultGroovyMethods.java:8841)
  2021-05-11 23:04:47.221         at org.codehaus.groovy.runtime.dgm$483.doMethodInvoke(Unknown Source)</p>