snippetMinor
How to check return status of parallel branches in jenkins pipeline
Viewed 0 times
branchesreturnjenkinsstatusparallelhowcheckpipeline
Problem
I am running a Jenkins job on multiple slaves. Following is the code structure:
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?
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 branchesNow, 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?
Solution
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
}Code Snippets
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
}Context
StackExchange DevOps Q#2711, answer score: 4
Revisions (0)
No revisions yet.