First of all, Thanks for looking into my concern.
I have below pipeline.
pipeline {
agent any
stages {
stage(‘one’) {
steps {
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
bat '''
echo “stage one”;
exit 1;
'''
echo "RESULT: ${currentBuild.result}"
//echo "RESULT2 ${currentBuild.stageResult}"
} //catch
}//steps
}//stage 1
stage('RunParallel') {
parallel {
stage(‘two’) {
steps {
bat '''
echo “stage two”;
exit 0;
'''
echo "RESULT: ${currentBuild.result}"
}
}
stage(‘three’) {
steps {
bat '''
echo “stage three”;
exit 0;
'''
echo "RESULT: ${currentBuild.result}"
}
}
stage(‘four’) {
steps {
bat '''
echo “stage four”;
exit 0;
'''
echo "RESULT: ${currentBuild.result}"
}
}
}//parallel
}//runParallel
stage(‘validate’) {
steps {
echo "RESULT: ${currentBuild.result}"
bat 'echo validation stage'
}
}
stage(‘five’) {
steps {
bat '''
echo “stag e 5”;
exit 0;
'''
}
}
}
post {
always {
bat '''
echo ‘I will always execute this!’
'''
}
}
}
My goal is:
- even if stage1 fails, I need to run stages 2,3,4
- a. if stage 1,2,3,4 fails, I have to report it in validation stage and fail the build b. if stage 1,2,3,4 succeeds, I need to pass validation and proceed towards stage5 and later stages
Right now I am able to do first step with catch block. And, stuck at step2. Can you guide on how to capture stage result and report failed stages.