1

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?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
  • Does this answer your question? [Determine Failed Stage in Jenkins Declarative Pipeline](https://stackoverflow.com/questions/43439093/determine-failed-stage-in-jenkins-declarative-pipeline) – zett42 May 16 '20 at 13:20
  • I've moved my answer [here](https://stackoverflow.com/a/61837364/7571258) as there are already too many similar questions like this. – zett42 May 16 '20 at 13:21

0 Answers0