如何在并行 运行 个阶段中获取失败的阶段名称?

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

我有一个管道,其中多个阶段 运行 并行,但如果任何阶段失败,我想获取其名称以显示失败的阶段。使用以下代码,即使它在第一阶段失败,即 Checking Redmine access,它总是显示最后阶段失败,即 Checking Reviewers list。这是因为它 运行 是并行的,并且最新分配的值被拾取。

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
            }
        }
    }
}

有什么办法可以得到并行 运行ning 阶段的完全失败阶段?或者如果父阶段名称作为失败阶段返回,我也可以。

我相信你可以为每个阶段使用一个 post { failure { 块:参见 https://www.jenkins.io/doc/book/pipeline/syntax/#post

pipeline {
    agent {
        label {
            label "<machine-ip>"
            customWorkspace "workspace/RedmineAndReviewboardProject/SVNCheckoutTest"
        }
    }
    stages {
        stage('Verify inputs') {

            parallel {
                stage('Checking Redmine access') {
                    steps {
                        script {
                            echo "Redmine"
                            sh'''hello'''
                        }
                    }
                    post {
                        failure {
                            script {
                                echo "Failed stage is ${STAGE_NAME}"
                            }
                        }
                    }
                }
                stage('Checking SVN access') {
                    steps {
                        script {
                            FAILED_STAGE = env.STAGE_NAME
                            echo "SVN"
                        }
                    }
                    post {
                        failure {
                            script {
                                echo "Failed stage is ${STAGE_NAME}"
                            }
                        }
                    }
                }
                stage('Checking Reviewers list') {
                    steps {
                        script {
                            FAILED_STAGE = env.STAGE_NAME
                            echo "Reviewer"
                        }
                    }
                    post {
                        failure {
                            script {
                                echo "Failed stage is ${STAGE_NAME}"
                            }
                        }
                    }
                }
            }
        }
    }
}