1
votes

I have a jenkins pipeline in which i have defined stages, I want to send email after specific stage number and at the end of the job.
For Example : Suppose i have a job in which i have 8 steps. I want that job will send success email after 6th stage if all 6 stages have successfully run. And again the same pipeline will send status after all stages are executed.

I know how to send email at the last(after all stages completed) but i am not able to find any solution for how to send email in between stages.

1

1 Answers

0
votes

You can do this with emailext:

Here is a sample:

pipeline {
    agent {
        label 'slave'
    }
    stages {
        stage('First Mail') {
            steps {
                emailext    to:     'send.mail@email',
                    from:       'send.from@email',
                    subject:    "First Mail", 
                    body:       "Here is the content of the first Mail"
            }
        }   
        stage('Second Mail') {
            steps {
                emailext    to:     'send.mail@email',
                    from:       'send.from@email',
                    subject:    "Secont Mail", 
                    body:       "Here is the content of the second Mail"
            }
        } 
    }
}

If you want to send the mails based on the result of the job, you can take a look at this answered question: Send email on jenkins pipeline failure