title: why is my for-each loop not working properly in parallel stages in jenkins scripted syntax?
body: <p>Consider the following code:</p>
  <pre><code>List&lt;String&gt; strs = ['foo', 'bar', 'baz']
  
  Map parallelStages = [:]
  for (s in strs) {
      String stageName = &quot;print $s&quot;
      parallelStages[stageName] = {
          stage(stageName) {
             println &quot;Hello, $s&quot;
          }
      }
      
  }
  parallel parallelStages
  </code></pre>
  <p>The output of this is</p>
  <pre><code>Hello, baz
  Hello, baz
  Hello, baz
  </code></pre>
  <p>Whereas I would have expected:</p>
  <pre><code>Hello, foo
  Hello, bar
  Hello, baz
  </code></pre>
  <p>This snippet works properly if I comment out the lines containing &quot;parallel&quot;.</p>
  <p>For the record, if I print out the content of <code>parallelStages</code> Map, I get <code>{print foo=org.jenkinsci.plugins.workflow.cps.CpsClosure2@38d330f7, print bar=org.jenkinsci.plugins.workflow.cps.CpsClosure2@30e6a23b, print baz=org.jenkinsci.plugins.workflow.cps.CpsClosure2@6abe446}</code></p>
  <p>Environment info:</p>
  <p>Jenkins: 2.332.2</p>
  <p>Pipeline plugin: 2.7</p>
  <p>Update: I could reproduce the same(?) problem in core groovy with Closures. Posted that one as a separate question:
  <a href="https://stackoverflow.com/questions/72899783/whats-wrong-with-this-groovy-for-loop-of-closures">What&#39;s wrong with this groovy for-loop of Closures?</a></p>