How would I store all failed stages of my declarative Jenkins pipeline

断了今生、忘了曾经 提交于 2020-07-10 01:47:06

问题


In my Jenkins pipeline, I have 15 stages. Now I have a post function at the end of the Jenkins file to send me an email about whether the whole process is failed or success. I would like to include all the stages that are failed in the email too. Using post in each stage is not a good idea, because I would receive 15 emails each time the job runs.

I am thinking of creating a list and save all failed env.STAGE_NAME in the list and print it at the end? But it would not allow me to do such a thing in the post.
I want to achieve something like:

pipeline {
    agent { label 'master'}
    stages {
        stage('1') {
            steps {
                echo 'make fail'
            }
        }
        stage('2') {
            steps {
                sh 'make fail'
            }
        }

        ...

        stage('15') {
            steps {
                sh 'make fail'
            }
        }
    }
    post {
        always {
            echo 'ok'
        }
        failure {
            "There are 3 stages have failed the test, which are: '1', '2' '15'"
        }
    }
}

How would I do it?

来源:https://stackoverflow.com/questions/61657304/how-would-i-store-all-failed-stages-of-my-declarative-jenkins-pipeline

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!