title: How to create stages dynamically / concatenate closures?
body: <p>What i want to achieve is building a list of stages with avoiding using when{}. Im trying to run parallel pipelines</p>
  <p>Here is example code</p>
  <pre><code>def stage_pull = {
          stage('pulling') {
              echo 'pulling'
          }
      }
   
  def stage_build = {
          stage(pulling) {
              echo 'building'
          }
      }
   
  def stage_deb = {
          stage(pulling) {
              echo 'deb file'
          }
      }
   
  def transformIntoStages(stage1,stage2) {
      //return stage1 + stage2
      //return {stage1;stage2}
      return stage1 &lt;&lt; stage2
  }
   
  def agent_list = [&quot;agent1&quot;, &quot;agent2&quot;]
  stepsForParallel = [:]
   
  stepsForParallel['agent1'] = transformIntoStages(stage_pull,stage_build)
  stepsForParallel['agent2'] = transformIntoStages(stage_pull,stage_deb)
   
  pipeline{
      agent any
      options {
          timestamps()
      }
      stages{
          stage('BUILD'){
              steps{
                  script{
                      parallel stepsForParallel
                  }
              }
          }
      }
  }
  </code></pre>
  <p>This is simplified version. In real project, the number of used stages will be different for each agent.</p>
  <p>I also have version with closures inside methods ...
  <a href="https://pastebin.com/gPJjPx59" rel="nofollow noreferrer">https://pastebin.com/gPJjPx59</a></p>
  <p>But none of this work.
  PS. I know matrix{}, i use it often but I dont want to use it in this particular case.</p>