title: Jenkins Pipeline - Iteration on stage level
body: <p>I've been reaching to a point that I really want to use iteration to save redundant code on stage level when building multi-platforms.
  Below is showcasing what I'm trying to do:</p>
  
  <pre><code>def map = [
          Bob  : 42,
          Alice: 54,
          Max  : 33
  ]
  
  pipeline {
      agent none
      stages {
          map.each { entry -&gt;
              stage ($entry.key) {
                  steps{
                      timestamps{
                          echo "$entry.value"
                      }
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>I think the concept here is pretty straight forward, but the builds are failing by telling me:</p>
  
  <pre><code>org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
  WorkflowScript: 13: Expected a stage @ line 13, column 9.
             map.each { entry -&gt;
             ^
  
  WorkflowScript: 12: No stages specified @ line 12, column 5.
         stages {
         ^
  
  2 errors
  </code></pre>
  
  <p>Does this mean jenkins have not yet support user to iterate on stages? If there's anything wrong with what I did, please let me know. Thanks!</p>
  
  <p>-----EDIT------</p>
  
  <p>BTW, @NonCPS is also tried, I don't think this is a <code>each</code> problem in pipeline script...</p>
  
  <pre><code>def map = [
          Bob  : 42,
          Alice: 54,
          Max  : 33
  ]
  
  pipeline {
      agent none
      stages {
          iter_stages map
      }
  }
  
  @NonCPS
  def iter_stages(dd) {
      dd.each { entry -&gt;
          stage ($entry.key) {
              steps{
                  timestamps{
                      echo "$entry.value"
                  }
              }
          }
      }
  }
  </code></pre>