Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-56139

Declarative pipeline multiple stages in parallel when use loop

      https://jenkins.io/blog/2018/07/02/whats-new-declarative-piepline-13x-sequential-stages/

      As the links above, can i use for loops to reuse code.

       

      def jobs = ["JobA", "JobB", "JobC"]
      def parallelStagesMap = jobs.collectEntries {
       ["${it}" : generateStage(it)]
      }
      def generateStage(job) {
          return {
              stage("stage: ${job}") {
                  stages {
                      stage ('complie') {
                          agent xxx
                          steps {
                              echo "${job} complie."
                          }
                      } 
                      stage(‘build') {
                          steps {
                              echo “${job} build."
                          }
                      }
                   } 
               }
           }
       }
      pipeline {
           agent any 
           stages {
               stage(‘xxx') {
                ...
                }
               stage('parallel stage') {
                   steps {
                       script{ 
                           parallel parallelStagesMap 
                       }
                   }
               }
           }
       }
      

       The above pipeline not work with error "No such DSL method ‘xxxx' found among steps "

          [JENKINS-56139] Declarative pipeline multiple stages in parallel when use loop

          jack sha created issue -
          jack sha made changes -
          Rank New: Ranked higher
          jack sha made changes -
          Description Original: [https://jenkins.io/blog/2018/07/02/whats-new-declarative-piepline-13x-sequential-stages/]

          As the links above, can i use for loops to reuse code.

          The following pipeline with error:

          {color:#FF0000}java.lang.NoSuchMethodError: No such DSL method 'stages' found among steps{color}
          {code:java}
          def jobs = ["JobA", "JobB", "JobC"]
          def parallelStagesMap = jobs.collectEntries {
           ["${it}" : generateStage(it)]
          }
          def generateStage(job) {
              return {
                  stage("stage: ${job}") {
                      stages {
                          stage ('complie') {
                              steps {
                                  echo "${job} complie."
                              }
                          }
                          stage(‘build') {
                              steps {
                                  echo “${job} build."
                              }
                          }
                       }
                   }
               }
           }
          pipeline {
               agent any
               stages {
                   stage(‘xxx') {
                    ...
                    }
                   stage('parallel stage') {
                       steps {
                           script{
                               parallel parallelStagesMap
                           }
                       }
                   }
               }
           }
          {code}
           
          New: [https://jenkins.io/blog/2018/07/02/whats-new-declarative-piepline-13x-sequential-stages/]

          As the links above, can i use for loops to reuse code.

           
          {code:java}
          def jobs = ["JobA", "JobB", "JobC"]
          def parallelStagesMap = jobs.collectEntries {
           ["${it}" : generateStage(it)]
          }
          def generateStage(job) {
              return {
                  stage("stage: ${job}") {
                      stages {
                          stage ('complie') {
                              agent xxx
                              steps {
                                  echo "${job} complie."
                              }
                          }
                          stage(‘build') {
                              steps {
                                  echo “${job} build."
                              }
                          }
                       }
                   }
               }
           }
          pipeline {
               agent any
               stages {
                   stage(‘xxx') {
                    ...
                    }
                   stage('parallel stage') {
                       steps {
                           script{
                               parallel parallelStagesMap
                           }
                       }
                   }
               }
           }
          {code}
           The above pipeline not work with error "No such DSL method ‘xxxx' found among steps "
          jack sha made changes -
          Priority Original: Minor [ 4 ] New: Major [ 3 ]
          Andrew Bayer made changes -
          Assignee Original: Andrew Bayer [ abayer ]

            Unassigned Unassigned
            jc_sha jack sha
            Votes:
            4 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated: