title: Iterating a groovy list in Jenkins Pipeline DSL
body: <p>I have a simple groovy list in my Pipeline that adds some maps:</p>
  
  <pre><code>def componentList = []
  
  def componentMapEntry1 = [:]
  componentMapEntry1['componentName']="Dashboard_Core"
  componentList &lt;&lt; componentMapEntry1
  
  def componentMapEntry2 = [:]
  componentMapEntry2['componentName']="Dashboard_Equities"
  componentList &lt;&lt; componentMapEntry2
  
  def cme3 = [:]
  cme3["componentName"] = "home"
  componentList &lt;&lt; cme3
  </code></pre>
  
  <p>When job is executed, I validate size</p>
  
  <pre><code>echo "size of list "+componentList.size()
  </code></pre>
  
  <p>...</p>
  
  <pre><code>[Pipeline] echo
  size of list 3
  </code></pre>
  
  <p>I can print it out the list</p>
  
  <pre><code>println componentList
  </code></pre>
  
  <p>...</p>
  
  <pre><code>[Pipeline] echo
  [{componentName=Dashboard_Core}, {componentName=Dashboard_Equities}, {componentName=home}]
  </code></pre>
  
  <p>I can do a for loop and iterate the list</p>
  
  <pre><code>for (i = 0; i &lt;componentList.size(); i++) {
      println componentList[i]
  }
  </code></pre>
  
  <p>...</p>
  
  <pre><code>[Pipeline] echo
  {componentName=Dashboard_Core}
  [Pipeline] echo
  {componentName=Dashboard_Equities}
  [Pipeline] echo
  {componentName=home}
  </code></pre>
  
  <p>So far all's well. </p>
  
  <p>Problem comes in when I try to use standard groovy iterator:</p>
  
  <pre><code>componentList.each {
      println "adding "+it.componentName
  }
  </code></pre>
  
  <p>In this case I only get the first element</p>
  
  <pre><code>[Pipeline] echo
  adding Dashboard_Core
  </code></pre>
  
  <p>Why would I only get the first element here? I've tried this several times and using .each() only seems to return first element. When I run the same code at groovy command line, it naturally <a href="http://naleid.com/blog/2008/12/01/groovy-makes-iteration-easy" rel="noreferrer">iterates as groovy would expect</a>. Is the .each{ } function getting overwritten somehow?</p>