<p>You can use snippet like</p>

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

<p>in declarative pipelines.</p>

<p><a href="https://jenkins.io/doc/book/pipeline/syntax/#post" rel="nofollow noreferrer" title="Changed">Changed</a> 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.</p>

CC BY-SA 4.0
2018-05-03T08:55:10.860Z
2018-05-03T08:55:10.860Z
Andrey Regentov
<p>This seems not to be possible at the moment with pipelines. See <a href="https://issues.jenkins-ci.org/browse/JENKINS-42644" rel="nofollow noreferrer">this Jira ticket</a>.</p>

CC BY-SA 4.0
2018-05-03T08:48:14.310Z
this jira ticket is about changing list of emailed users, not the triggers from question
Andrey Regentov
CC BY-SA 3.0
2018-04-05T08:56:36.127Z
2018-04-05T08:56:36.127Z
woernsn
<p>Before Pipeline, I used <a href="https://wiki.jenkins.io/display/JENKINS/Email-ext+plugin" rel="nofollow noreferrer">Email-ext plugin</a> to define triggers for sending emails (on first failure, and when back to success).</p>

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

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

<jenkins><continuous-integration><jenkins-pipeline><jenkins-plugins>
How to use Jenkins Pipeline and choose triggers for email notifications?
Oren Shpigel
# How to use Jenkins Pipeline and choose triggers for email notifications?

(Asked by: username_0 on 2018-03-29)

Before Pipeline, I used [Email-ext plugin](https://wiki.jenkins.io/display/JENKINS/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)

**Tags:** jenkins, continuous-integration, jenkins-pipeline, jenkins-plugins


---

## 2 answers

### Answer by username_1 on 2018-05-03. Score: 1 | Accepted answer

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.


---

### Answer by username_2 on 2018-04-05. Score: 1

This seems not to be possible at the moment with pipelines. See [this Jira ticket](https://issues.jenkins-ci.org/browse/JENKINS-42644).

> **Comments:**
> **username_1**: this jira ticket is about changing list of emailed users, not the triggers from question  

---

