How to get failed stage name during parallel run of stages?

12 views
Skip to first unread message

Gajanan Mahajan

unread,
Oct 7, 2020, 3:32:42 PM10/7/20
to Jenkins Users
I've a pipeline where multiple stages run in parallel but if any of the stages fails, I want to get its name to show failed stage. With following code, even if it fails in first stage ie `Checking Redmine access`, it always show last stage as failed i.e. `Checking Reviewers list`. This is because it runs in parallel and latest assigned value is picked up.

    pipeline {
        agent {
            label {
                label "<machine-ip>"
                customWorkspace "workspace/RedmineAndReviewboardProject/SVNCheckoutTest"
            }
        }
        stages {
            stage('Verify inputs') {
    
                parallel {
                    stage('Checking Redmine access') {
                        steps {
                            script {
                                FAILED_STAGE = env.STAGE_NAME
                                echo "Redmine"
                                sh'''hello'''
                            }
                        }
                    }
                    stage('Checking SVN access') {
                        steps {
                            script {
                                FAILED_STAGE = env.STAGE_NAME
                                echo "SVN"
                            }
                        }
    
                    }
                    stage('Checking Reviewers list') {
                        steps {
                            script {
                                FAILED_STAGE = env.STAGE_NAME
                                echo "Reviewer"
                            }
                        }
                    }
    
                }
    
            }
        }
        post {
            failure {
                script {
                    echo "Failed stage is " + FAILED_STAGE
                }
            }
        }
    }

Is there any way I can get exactly failed stage of parallel running stages? or it will be also ok with me if parent stage name is returned as failed stage.

Reply all
Reply to author
Forward
0 new messages