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

          Hi,

          I have the same issue, trying to dynamically create parallel steps which have sequential steps inside them. 

          Pietro Ferrari added a comment - Hi, I have the same issue, trying to dynamically create parallel steps which have sequential steps inside them. 

          loong zhou added a comment - - edited

          I also have the same issue. If sequential-stages is supported, the senerio

          stage('parallel stage') {
            steps {
              script{ parallel parallelStagesMap }
            }
          }
          

          would be common.

          So can u fix it?  Otherwize we have to use scripted pipeline instead.

          loong zhou added a comment - - edited I also have the same issue. If sequential-stages is supported, the senerio stage( 'parallel stage' ) { steps { script{ parallel parallelStagesMap } } } would be common. So can u fix it?  Otherwize we have to use scripted pipeline instead.

          Ryan added a comment -

          As a use case for this enhancement, we are trying to build against multiple Docker images (different architectures) in parallel using a similar method to the one described above. This fix would be a huge improvement to our build process and cut down on code duplication.

          Ryan added a comment - As a use case for this enhancement, we are trying to build against multiple Docker images (different architectures) in parallel using a similar method to the one described above. This fix would be a huge improvement to our build process and cut down on code duplication.

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

              Created:
              Updated: