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

build job won't trigger if filled in for loop

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Minor
    • Resolution: Not A Defect
    • Component/s: _unsorted
    • Labels:
      None
    • Similar Issues:

      Description

      I found parallel do behave differently when using a for loop or an each loop when filling the list.

      def sub_jobs = [:]
          for (platform in selected_platforms) {
              sub_jobs[platform] = {
                  build job:  job_name,
                      parameters: [
                          string(name: 'Platform', value: platform),
                          string(name: 'Upstream Project Build Number', value: BUILD_NUMBER)
                      ], wait: true
              }
          }
      parallel sub_jobs
      

      results in:

      [Pipeline] parallel
      [Pipeline] { (Branch: WIN10)
      [Pipeline] { (Branch: U1604)
      [Pipeline] build (Building Product) 
      11:36:56  Scheduling project: Product
      [Pipeline] build (Building Product)
      11:36:56  Scheduling project: Product
      11:37:01  Starting building: Product #37
      11:37:01  Starting building: Product #37
      

      So only one platform is build in this case.

      But an each loop works:

      def sub_jobs = [:]
      selected_platforms.each {
          sub_jobs[it] = {
              build job: job_name,
                  parameters: [
                      string(name: 'Platform', value: it),
                      string(name: 'Upstream Project Build Number', value: BUILD_NUMBER)
                  ], wait: true
          }
      }
      parallel sub_jobs
       

       

      [Pipeline] parallel
      [Pipeline] { (Branch: WIN10)
      [Pipeline] { (Branch: U1604)
      [Pipeline] build (Building Product)
      11:36:56  Scheduling project: Product
      [Pipeline] build (Building Product)
      11:36:56  Scheduling project: Product
      11:37:01  Starting building: Product #38
      11:37:01  Starting building: Product #39
      

      Running on Jenkins 2.222.1 Docker LTS Image

        Attachments

          Activity

          Hide
          mwinter69 Markus Winter added a comment -

          This is not a bug. The following will do the trick:

          def sub_jobs = [:]
              for (platform in selected_platforms) {
                  def pf = platform
                  sub_jobs[pf] = {
                      build job:  job_name,
                          parameters: [
                              string(name: 'Platform', value: pf),
                              string(name: 'Upstream Project Build Number', value: BUILD_NUMBER)
                          ], wait: true
                  }
              }
          parallel sub_jobs
          

          (See Pipeline Exampels)

           

          Show
          mwinter69 Markus Winter added a comment - This is not a bug. The following will do the trick: def sub_jobs = [:] for (platform in selected_platforms) { def pf = platform sub_jobs[pf] = { build job: job_name, parameters: [ string(name: 'Platform' , value: pf), string(name: 'Upstream Project Build Number ' , value: BUILD_NUMBER) ], wait: true } } parallel sub_jobs (See Pipeline Exampels )  
          Hide
          ngerke Nils Gerke added a comment -

          So platform is mutable in the for loop, good to know

          Show
          ngerke Nils Gerke added a comment - So platform is mutable in the for loop, good to know

            People

            • Assignee:
              Unassigned
              Reporter:
              ngerke Nils Gerke
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: