title: Jenkins pipeline (parallel && dynamically)?
body: <h1>Question</h1>
  
  <p>I have simple parallel pipeline (see code) which I use together with Jenkins 2.89.2. Additionally I use parameters and now want to be able to in-/decrease the number of deployVM A..Z stages automatically by providing the parameter before job execution.</p>
  
  <p>How can I dynamically build my pipeline by providing a parameter?</p>
  
  <p>Researched so far:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/40082261/jenkins-pipeline-script-created-dynamically">Jenkins pipeline script created dynamically</a> - Not getting this to work with my Jenkins version</li>
  <li><a href="https://stackoverflow.com/questions/42837066/can-i-create-dynamically-stages-in-a-jenkins-pipeline">Can I create dynamically stages in a Jenkins pipeline?</a> - Not working either</li>
  </ul>
  
  <h1>Code</h1>
  
  <p>The pseudo code of what I want - dynamic generation:</p>
  
  <pre><code>pipeline {
  
      agent any
  
      parameters {
          string(name: 'countTotal', defaultValue: '3')
      }
  
      stages {
  
         stage('deployVM') {
  
          def list = [:]
          for(int i = 0; i &lt; countTotal.toInteger; i++) {
              list += stage("deployVM ${i}") {
                  steps {
                      script {
                          sh "echo p1; sleep 12s; echo phase${i}"
                      }
  
                  }
              }
          }
  
          failFast true
          parallel list
         }
  
     }
  
  }
  </code></pre>
  
  <p>The code I have so far - executes parallel but is static:</p>
  
  <pre><code>pipeline {
  
      agent any
      stages {
  
         stage('deployVM') {
          failFast true
          parallel {
              stage('deployVM A') {
                  steps {
                      script {
                          sh "echo p1; sleep 12s; echo phase1"
                      }
  
                  }
              }
              stage('deployVM B') {
                  steps {
                      script {
                          sh "echo p1; sleep 20s; echo phase2"
                      }
  
                  }
              }
          }
         }
  
     }
  
  }
  </code></pre>