title: Jenkins pipeline script created dynamically
body: <p>I am using a jenkins pipeline project. In the script I would like to write the <em>parallel</em> block in a dynamic way, since the number of nodes can change. For instance, from this:</p>
  
  <pre><code>parallel(
  node1: {
      node(){
          stage1()
          stage2()
          ...
      }
  },
  node2: {
      node(){
          stage1()
          stage2()
          ...
      }
  },
  ...
  )
  </code></pre>
  
  <p>to something like this</p>
  
  <pre><code>for (int i = 0; i &lt; $NODE_NUMBER; i++) {
    "node${i}": {
      node (’namenode-' + ${i}) {
        something()
      }
  }
  </code></pre>
  
  <p>but this way doesn’t work, Groovy/Jenkins is not happy about this syntax. Can someone suggest a better way for doing this?</p>