Answers: <p>Something needs to be different in other_job2 for tests['x'] and tests['y'].</p>
  
  <p>Example(untested),</p>
  
  <pre><code>for (f in [ 'x', 'y' ]) { {
      {some code}
      build job: "other_job2", parameters: [file_params, string(name:'dummy', value: "${f}")], wait: true, propagate: true
      // the dummy parameter is for preventing mutation
  }
  </code></pre>
  
  <p>More info:
  <a href="https://www.jenkins.io/doc/pipeline/examples/#jobs-in-parallel" rel="nofollow noreferrer">https://www.jenkins.io/doc/pipeline/examples/#jobs-in-parallel</a></p>
  
Answers: CC BY-SA 4.0
Answers: 2020-05-05T20:28:53.287Z
Answers: thanks a lot, you pointed me the right link, can you edit your answer by pasting `the dummy parameter is for preventing mutation...` comment line, I added `for (k in [ 'x', 'y' ]) { def f = k` ... and it started working.
Answers: rodee
Answers: CC BY-SA 4.0
Answers: 2020-05-05T20:41:40.783Z
Answers: I spent lots of time figuring this, you saved my time, but please add this info too to your answer, so it will be useful for others `def index = i //if we tried to use i below, it would equal 4 in each job execution.` which I see in the link you pasted.
Answers: rodee
Answers: CC BY-SA 4.0
Answers: 2020-05-05T20:19:38.323Z
Answers: 2020-05-05T20:33:23.797Z
Answers: 2020-05-05T20:33:23.797Z
Answers: karthikeayan
Answers: <p>If you are using &quot;Generic Webhook Trigger Plugin&quot; you need to update plugin to the latest version (above 1.86.0) and enable &quot;Allow several triggers per build&quot; within Job configurations.</p>
  
Answers: CC BY-SA 4.0
Answers: 2023-04-04T08:59:08.353Z
Answers: 2023-04-04T08:59:08.353Z
Answers: Amir Babic
Body: <p>I have this test pipeline code, it runs 2 build on different nodes on <code>build_servers</code> as expected. </p>
  
  <pre><code>pipeline {
      agent { label 'myserver' }
      stages {
          stage('1') {
              steps {
                  script {
                      def tests = [:]
                      for (f in [ 'x', 'y' ]) {
                          tests["${f}"] = {
                              node('build_servers') {
                                  stage('Clean Workspace') {
                                       echo "cleaning up Ws ${f}"
                                       step([$class: 'WsCleanup'])
                                  }
                                  stage('create Wspace txt file') {
                                          script {
                                              props="Wspace=${workspace}"
                                              dir ( 'wspace') {
                                                      writeFile file: 'params.txt', text: props
                                              }
                                          }
                                  }
                                  stage('Run other job') {
                                      script {
                                          println('calling other project')
                                          props = readProperties file: "wspace/params.txt"
                                             file_params = props.collect {
                                                  string(name: it.key, value: it.value)
                                          }
                                          build job: "other_job2", parameters: file_params, wait: true, propagate: true
                                      }
                                  }
                              }
                          }
                      }
                      parallel tests
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>I expect it to trigger 2 different builds on <code>other_job2</code>, but it submits just one job and both <code>tests['x'] and tests['y']</code> waits for the same job to finish, why is that? should it not create 2 different  jobs in <code>other_job2</code> project, one for <code>x</code> and one for <code>y</code>?</p>
  
  <p>in the console output, I see build #5 for both [x] and [y] exactly as shown below:</p>
  
  <pre><code>[x] Starting building: TEST » other_job2 #5
  [y] Starting building: TEST » other_job2 #5
  </code></pre>
  
  <p>Also, I am printing <code>${f}</code> in <code>echo "cleaning up WS...</code> line, I expected to see both x and y, but I see only <code>cleaning up Ws y</code> printed for both <code>[x]</code> and <code>[y]</code> as below</p>
  
  <pre><code>[x] cleaning up Ws y
      [Pipeline] cleanWs
  [x] [WS-CLEANUP] Deleting project workspace...
      [WS-CLEANUP] Deferred wipeout is used...
      [WS-CLEANUP] done
      [Pipeline] echo
  [y] cleaning up Ws y
      [Pipeline] cleanWs
  [y] [WS-CLEANUP] Deleting project workspace...
      [WS-CLEANUP] Deferred wipeout is used...
      [WS-CLEANUP] done
  </code></pre>
  
Tags: <jenkins><jenkins-pipeline><jenkinsfile>
Title: Running parallel builds from jenkins pipeline job triggers and waits for same job on other project
UserDisplayName: rodee
ThreadText: # Running parallel builds from jenkins pipeline job triggers and waits for same job on other project
  
  (Asked by: username_0 on 2020-05-05)
  
  I have this test pipeline code, it runs 2 build on different nodes on `build_servers` as expected.
  
  ```
  pipeline {
      agent { label 'myserver' }
      stages {
          stage('1') {
              steps {
                  script {
                      def tests = [:]
                      for (f in [ 'x', 'y' ]) {
                          tests["${f}"] = {
                              node('build_servers') {
                                  stage('Clean Workspace') {
                                       echo "cleaning up Ws ${f}"
                                       step([$class: 'WsCleanup'])
                                  }
                                  stage('create Wspace txt file') {
                                          script {
                                              props="Wspace=${workspace}"
                                              dir ( 'wspace') {
                                                      writeFile file: 'params.txt', text: props
                                              }
                                          }
                                  }
                                  stage('Run other job') {
                                      script {
                                          println('calling other project')
                                          props = readProperties file: "wspace/params.txt"
                                             file_params = props.collect {
                                                  string(name: it.key, value: it.value)
                                          }
                                          build job: "other_job2", parameters: file_params, wait: true, propagate: true
                                      }
                                  }
                              }
                          }
                      }
                      parallel tests
                  }
              }
          }
      }
  }
  
  ```
  
  I expect it to trigger 2 different builds on `other_job2`, but it submits just one job and both `tests['x'] and tests['y']` waits for the same job to finish, why is that? should it not create 2 different jobs in `other_job2` project, one for `x` and one for `y`?
  
  in the console output, I see build #5 for both [x] and [y] exactly as shown below:
  
  ```
  [x] Starting building: TEST » other_job2 #5
  [y] Starting building: TEST » other_job2 #5
  
  ```
  
  Also, I am printing `${f}` in `echo "cleaning up WS...` line, I expected to see both x and y, but I see only `cleaning up Ws y` printed for both `[x]` and `[y]` as below
  
  ```
  [x] cleaning up Ws y
      [Pipeline] cleanWs
  [x] [WS-CLEANUP] Deleting project workspace...
      [WS-CLEANUP] Deferred wipeout is used...
      [WS-CLEANUP] done
      [Pipeline] echo
  [y] cleaning up Ws y
      [Pipeline] cleanWs
  [y] [WS-CLEANUP] Deleting project workspace...
      [WS-CLEANUP] Deferred wipeout is used...
      [WS-CLEANUP] done
  
  ```
  
  **Tags:** jenkins, jenkins-pipeline, jenkinsfile
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2020-05-05. Score: 2 | Accepted answer
  
  Something needs to be different in other\_job2 for tests['x'] and tests['y'].
  
  Example(untested),
  
  ```
  for (f in [ 'x', 'y' ]) { {
      {some code}
      build job: "other_job2", parameters: [file_params, string(name:'dummy', value: "${f}")], wait: true, propagate: true
      // the dummy parameter is for preventing mutation
  }
  
  ```
  
  More info:
  <https://www.jenkins.io/doc/pipeline/examples/#jobs-in-parallel>
  
  > **Comments:**
  > **username_0**: thanks a lot, you pointed me the right link, can you edit your answer by pasting `the dummy parameter is for preventing mutation...` comment line, I added `for (k in [ 'x', 'y' ]) { def f = k` ... and it started working.  
  > **username_0**: I spent lots of time figuring this, you saved my time, but please add this info too to your answer, so it will be useful for others `def index = i //if we tried to use i below, it would equal 4 in each job execution.` which I see in the link you pasted.  
  
  ---
  
  ### Answer by username_2 on 2023-04-04. Score: 0
  
  If you are using "Generic Webhook Trigger Plugin" you need to update plugin to the latest version (above 1.86.0) and enable "Allow several triggers per build" within Job configurations.
  
  
  ---
  
  