<p>I tried storing the slave job part status in a file and stashing it on node and then unstashing it back on master. It works but I am looking for a cleaner way. Following is the current approach i am using:</p>

<pre><code>def branches = [:]
def allNodes = Jenkins.getInstance().getNodes()
for (int i =0; i &lt; allNodes.size(); i++) {
String nodeName = allNodes[i].name.toString()
branches[nodeName] = {
    node(nodeName) { 
    .
    .
    String outputFile = nodeName + "-output"
    writeFile file: outputFile, text: result.toString()
    stash includes: "*output", name: outputFile
    }
}
parallel branches

for (int i = 0; i &lt; allNodes.size(); i++) 
{
    String filename = allNodes[i].name.toString() + "-output"
    unstash filename
    def value = readFile filename

    // Mark node offline based on the variable value
}
</code></pre>

CC BY-SA 4.0
2019-02-25T11:37:02.523Z
using this as well. hope will find a cleaner way, too.
Vano
CC BY-SA 4.0
2024-01-05T08:57:16.217Z
Nothing changed in 2024
Aleksander Stelmaczonek
CC BY-SA 3.0
2017-11-28T06:50:38.127Z
2017-11-28T06:50:38.127Z
Anirudh Singh
<p>You may want to try the <a href="http://wiki.jenkins-ci.org/display/JENKINS/Join+Plugin" rel="nofollow noreferrer">Join plugin</a>. Some more details about this plugin (from the linked page):</p>

<blockquote>
  <p>This plugin allows a job to be run after all the immediate downstream jobs have completed. In this way, the execution can branch out and perform many steps in parallel, and then run a final aggregation step just once after all the parallel work is finished.</p>
  
  <p>The plugin is useful for creating a 'diamond' shape project dependency.   This means there is a single parent job that starts several downstream jobs. Once those jobs are finished, a single aggregation job runs.</p>
</blockquote>

<p>For more details on that, refer to my self answered question about "<a href="https://devops.stackexchange.com/q/717/40">Why trigger something remotely (using Jenkins) and then just forget about it?</a>".</p>

CC BY-SA 4.0
2019-02-25T11:36:14.653Z
IMHO the mentioned plugin designed fir chaining jobs not for parallel pipeline steps
Vano
CC BY-SA 3.0
2017-11-27T10:14:28.160Z
2017-11-27T18:22:23.277Z
2017-11-27T18:22:23.277Z
Pierre.Vriens
<p>I am running a Jenkins job on multiple slaves. Following is the code structure:</p>

<pre><code>def branches = [:]
def allNodes = Jenkins.getInstance().getNodes()
for (int i =0; i &lt; allNodes.size(); i++) {
branches[allNodes[i].name.toString()] = {
    node(allNodes[i].name.toString()) { 
    .
    .
    stuff
    }
}
parallel branches
</code></pre>

<p>Now, I want to get the status of the job parts running on nodes so that in case some job part fails on some node I can mark that node as offline. Is there any way to do this?</p>

<jenkins><jenkins-pipeline><jenkinsfile><groovy>
How to check return status of parallel branches in jenkins pipeline
Anirudh Singh
# How to check return status of parallel branches in jenkins pipeline

(Asked by: username_0 on 2017-11-27)

I am running a Jenkins job on multiple slaves. Following is the code structure:
def branches = [:]
def allNodes = Jenkins.getInstance().getNodes()
for (int i =0; i < allNodes.size(); i++) {
branches[allNodes[i].name.toString()] = {
    node(allNodes[i].name.toString()) { 
    .
    .
    stuff
    }
}
parallel branches

Now, I want to get the status of the job parts running on nodes so that in case some job part fails on some node I can mark that node as offline. Is there any way to do this?

**Tags:** jenkins, jenkins-pipeline, jenkinsfile, groovy


---

## 2 answers

### Answer by username_0 on 2017-11-28. Score: 4

I tried storing the slave job part status in a file and stashing it on node and then unstashing it back on master. It works but I am looking for a cleaner way. Following is the current approach i am using:
def branches = [:]
def allNodes = Jenkins.getInstance().getNodes()
for (int i =0; i < allNodes.size(); i++) {
String nodeName = allNodes[i].name.toString()
branches[nodeName] = {
    node(nodeName) { 
    .
    .
    String outputFile = nodeName + "-output"
    writeFile file: outputFile, text: result.toString()
    stash includes: "*output", name: outputFile
    }
}
parallel branches

for (int i = 0; i < allNodes.size(); i++) 
{
    String filename = allNodes[i].name.toString() + "-output"
    unstash filename
    def value = readFile filename

    // Mark node offline based on the variable value
}

> **Comments:**
> **username_1**: using this as well. hope will find a cleaner way, too.  
> **username_2**: Nothing changed in 2024  

---

### Answer by username_3 on 2017-11-27. Score: 3

You may want to try the [Join plugin](http://wiki.jenkins-ci.org/display/JENKINS/Join+Plugin). Some more details about this plugin (from the linked page):

> This plugin allows a job to be run after all the immediate downstream jobs have completed. In this way, the execution can branch out and perform many steps in parallel, and then run a final aggregation step just once after all the parallel work is finished.
>
> The plugin is useful for creating a 'diamond' shape project dependency. This means there is a single parent job that starts several downstream jobs. Once those jobs are finished, a single aggregation job runs.

For more details on that, refer to my self answered question about "[Why trigger something remotely (using Jenkins) and then just forget about it?](https://devops.stackexchange.com/q/717/40)".

> **Comments:**
> **username_1**: IMHO the mentioned plugin designed fir chaining jobs not for parallel pipeline steps  

---

