I got code that list all branches and stages for my pipeline
def List getBranchResults() {
def visitor = new PipelineNodeGraphVisitor(currentBuild.rawBuild)
echo "${visitor}"
def branches = visitor.pipelineNodes.findAll{
it.type == FlowNodeWrapper.NodeType.PARALLEL
}
def stages = visitor.pipelineNodes.findAll{
it.type == FlowNodeWrapper.NodeType.STAGE
}
echo "${stages}"
def results = branches.collect{
branch -> [
id: branch.id,
displayName: branch.displayName,
result: "${branch.status.result}",]
}
echo "Branch results:\n" + results.join('\n')
}
def build_jobs = [:]
def build_results
build_jobs['1'] = {
node('builder'){
stage('A'){
sh 'echo 1'
}
stage('B'){
"error"
}
}
}
build_jobs['2'] = {
node('builder'){
sh 'echo 2'
}
}
build_jobs['3'] = {
node('builder'){
stage('A'){
sh 'echo 3'
}
stage('B'){
}
}
}
parallel build_jobs
getBranchResults( )
How I can connect between those two ? I want to print for each branch it stages. Also I want to print the failed stage (if it exists) for each branch
For example:
Branch results:
[id:15, displayName:1, result:SUCCESS]
Stage results for 1:
[id=55,displayName=A,type=STAGE]
[id=25,displayName=B,type=STAGE] - FAILURE
We can associate branches and child stages by querying
FlowNode.allEnclosingIds
for each node. If this list contains branch ID, we have a child stage.I have implemented this in function
getStageResultsForBranch()
below. It appears to work with the sample code. If stages have nested sub stages, it will return these too, which may not be what you want.Sample code:
(I have removed the build job nodes for testing)
Output: