# How to use Jenkins Pipeline and choose triggers for email notifications?

Before Pipeline, I used Email-ext plugin to define triggers for sending emails (on first failure, and when back to success).

But in the Pipeline version, I can't control the triggers, I can only "send always", or send based on current build result.

How do I send emails in pipeline based on more general triggers? (first failure, first success, etc)

## 2 Answers

You can use snippet like

post {
changed {
emailext body: '$DEFAULT_CONTENT', recipientProviders: [brokenTestsSuspects(), brokenBuildSuspects(), developers()], subject: '$DEFAULT_SUBJECT'
}
}


in declarative pipelines.

Changed post-condition is called when the build result is changed (i.e. of first failure and back to success). There are post-conditions like "regression" if you want more control.

This seems not to be possible at the moment with pipelines. See this Jira ticket.

• this jira ticket is about changing list of emailed users, not the triggers from question – Andrey Regentov May 3 '18 at 8:48