• Stars
    star
    338
  • Rank 120,377 (Top 3 %)
  • Language
    Java
  • License
    MIT License
  • Created over 13 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Jenkins Email Extension Plugin

Email Extension Plugin

Introduction

This plugin extends the Mailer plugin's functionality by giving you more control. It provides customization of three areas:

Triggers

Select the conditions that should cause an email notification to be sent.

Content

Specify the content of each triggered email’s subject and body.

Recipients

Specify who should receive an email when it is triggered.

Questions and issues

If you need help, please post on the Jenkins users mailing list or Stack Overflow.

Report bugs and requests for enhancement in the Jenkins issue tracker (no support tickets, please). Use the email-ext-plugin component in the JENKINS project.

Getting started

System-wide configuration

Before using this plugin from a project, you must first configure some system-wide settings. Go to the Jenkins system-wide configuration page (Manage Jenkins, Configure System).

The configuration for this plugin can be found in the section entitled Extended E-mail Notification. This configuration should match the settings for your SMTP mail server. This section mirrors that of the Mailer plugin in the E-mail Notification section; however, there are a few additions. The fields labeled Default Subject and Default Content allow you to configure the subject and content on a system-wide level. The field labeled Default Recipients can be used to set a default list of email addresses for all projects using this plugin (and can be overridden at the project level); this can be used to greatly simplify the configuration you need to do for all projects.

Project configuration

For a project to use this plugin, you need to enable it in the project configuration page. In the Post-build Actions section, click on Add post-build action and then select Editable Email Notification.

There are three main fields that you can edit when this plugin is enabled:

Project Recipient List

This is a comma (or whitespace) separated list of email recipients. Allows you to specify a single recipient list for each email that is sent.

Default Subject

This allows you to configure a token (more about tokens later) that can be used to easily configure all email subjects for the project.

Default Content

Same as Default Subject, but for the email body instead of the subject.

Pipeline step

This plugin can be used from Pipeline via the emailext step:

emailext body: 'Test Message',
    subject: 'Test Subject',
    to: '[email protected]'

Use the recipientProviders parameter to add additional recipients. For example, to add all the people who caused a change in the change set and the user who initiated the build:

emailext body: 'Test Message',
    recipientProviders: [developers(), requestor()],
    subject: 'Test Subject',
    to: '[email protected]'

The recipient providers from this plugin can also be used with the Mailer plugin. For example, to add culprits and the user who initiated the build:

step([$class: 'Mailer',
  notifyEveryUnstableBuild: true,
  recipients: emailextrecipients([culprits(), requestor()])])

Usage

To see the advanced configuration for this plugin, click on the Advanced button. This section allows you to specify recipients for each type of email trigger as well as a pre-send script that can be used to modify the email prior to sending.

Pre-send scripts and post-send scripts

This feature allows you to write a script that can modify the MimeMessage object before or after sending the email. This allows adding custom headers, modifying the body, etc. Predefined variables include:

msg (jakarta.mail.internet.MimeMessage)

The MIME email message object, which can be modified.

logger (java.io.PrintStream)

A PrintStream that can be used to log messages to the build log.

build (hudson.model.AbstractBuild)

The build this message belongs to (only use with Freestyle projects).

run (hudson.model.Run)

The build this message belongs to (may be used with Freestyle projects or Pipeline).

cancel (boolean)

When set to true, cancels the sending of the email.

Triggers

By default, the only trigger configured is the Failure - Any trigger. To add more triggers, select one from the drop-down and it will be added to the list. To see what conditions must be met for this plugin to send an email, click on the "?" (question mark) next to the trigger.

Extended Email Publisher Triggers

The following triggers are available as part of the Extended Email Publisher plugin, other plugins can provide triggers as well through the extension point defined in the Extended Email Publisher:

Aborted

An email will be sent if the build status is "Aborted". A build is aborted via the UI or API, but normally requires some sort of user intervention to occur. An aborted build is stopped during its execution.

Always

Always triggers an email after the build, regardless of the status of the build.

Before Build

An email will be sent when the build begins, but after SCM polling has completed.

Failure → Unstable (Test Failures)

An email will be sent any time the build goes from failing (compilation or build step failures), to unstable (unit test failures). This basically means that all the builds steps were successful, but there are still tests failing.

Failure - Any

An email will be sent any time the build fails. If the "Failure - Still" trigger is configured, and the previous build status was "Failure", then the "Failure - Still" trigger will send an email instead.

Failure - 1st

An email will be sent when the build status changes from "Success" to "Failure".

Failure - 2nd

An email will be sent when the build fails twice in a row after a successful build.

Failure - Still

An email will be sent if the build status is "Failure" for two or more builds in a row.

Failure - X

An email will be sent when the build fails X times in a row after a successful build

Fixed

An email will be sent when the build status changes from "Failure" or "Unstable" to "Success".

Not Built

An email will be sent if the build status is "Not Built". This status code is used in a multi-stage build (like maven2) where a problem in earlier stage prevented later stages from building.

Script - After Build

Allows the user to define a script that is executed to determine if an email should be sent AFTER the build occurs. The last line of the script should resolve to true to send an email, or false to not send an email. See Script Trigger Options below for parameters available to the script.

Script - Before Build

Allows the user to define a script that is executed to determine if an email should be sent BEFORE the build occurs. The last line of the script should resolve to true to send an email, or false to not send an email. See Script Trigger Options below for parameters available to the script.

Status Changed

An email will be sent if the build status changes.

Success

An email will be sent if the build status is "Successful". If the "Fixed" trigger is configured, and the previous build status was "Failure" or "Unstable", then the "Fixed" trigger will send an email instead.

Test Improvement

An email will be sent any time there is an improvement. A build is considered to have improved whenever it has fewer test failures than the previous build. If the current failure count went to 0 (no more test failures) this trigger will NOT send an email.

Test Regression

An email will be sent any time there is a regression. A build is considered to regress whenever it has more failures than the previous build, or if there are new tests that failed.

Unstable (Test Failures)

An email will be sent any time the build is unstable. A build is unstable if there are test failures, but all the build steps completed successfully. If the "Unstable - Still" trigger is configured, and the previous build status was "Unstable", then the "Unstable - Still" trigger will send an email instead.

Unstable (Test Failures) - 1st

An email will be sent when the build status changes from anything to "Unstable".

Unstable (Test Failures) - Still

An email will be sent if the build status is "Unstable" for two or more builds in a row. A build is unstable if there are test failures, but all the build steps completed successfully.

Unstable (Test Failures)/Failure → Success

An email will be sent when the build status changes from "Failure" or "Unstable" to "Success". Intermediate "Aborted" builds are ignored.

Common Trigger Options

Once you have added a trigger, you have several common options (there may be additional options available depending on the trigger implementation):

Recipient List

Add this recipient provider if you would like to have the email sent to the Project Recipient List configured above.

Developers

Add this recipient provider to send the email to anyone who checked in code for the last build. This plugin will generate an email address based on the committer’s ID and an appended Default user e-mail suffix from the Extended E-mail Notification section of the Configure System page. For example, if a change was committed by someone with an ID of first.last, and the default user e-mail suffix is @example.com, then an email will be sent to [email protected].

Requestor

Add this recipient provider to send an email to the user who initiated the build (if initiated by a user manually).

Include Culprits

If this recipient provider and the Developers recipient provider are added, emails will include everyone who committed since the last successful build.

Previous

Add this recipient provider to send an email to the the culprits, requestor and developers of the previous build(s).

Advanced

Configure properties at a per-trigger level:

Recipient List

A comma (or whitespace) separated list of email address that should receive this email if it is triggered. This list is appended to the Project Recipient List described above.

Subject

Specify the subject line of the selected email.

Content

Specify the body of the selected email.

Script Trigger Options

You can also add Script - After Build or Script - Before Build triggers to a project to use Groovy scripts to define before or after the build whether or not the email will be sent. The script is defined in the Groovy Script section of the trigger. There are four objects added to the model for the script to use to interact with the build:

out (java.io.PrintStream)

A PrintStream that can be used to log messages to the build log.

build (hudson.model.AbstractBuild)

This is the current build, usually a subclass of AbstractBuild.

project (hudson.model.AbstractProject)

The project object that the current build was started from, usually a subclass of AbstractProject.

rooturl (String)

The Jenkins instance root URL, useful for links.

The last line in the script should resolve to a boolean (true or false):

Script - Before Build:
// this could be used to notify people that a new build is happening
build.previousBuild.result.toString().equals('FAILURE')
Script - After Build:
// only send am email if the build failed and 'mickeymouse' had a commit
build.result.toString().equals('FAILURE') && build.hasParticipant(User.get('mickeymouse'))
// only send an email if the word {{ERROR}} is found in build logs
build.logFile.text.readLines().any { it =~ /.*ERROR.*/ }

Tokens

This plugin uses tokens to allow dynamic data to be inserted into recipient list, subject line, or body. A token is a string that starts with a $ (dollar sign) and is terminated by whitespace. When an email is triggered, a token in the subject or content fields will be replaced dynamically by the actual value that it represents. Also, the value of a token can contain other tokens that will themselves be replaced by actual content. For instance, the $DEFAULT_SUBJECT token is replaced by the text (and other tokens) that is in the Default Subject field from the Extended E-mail Notification section of the Configure System page. Similarly, the $PROJECT_DEFAULT_SUBJECT token will be replaced by the value of the Default Subject field from the project configuration page.

This plugin sets the email content fields with default values when you enable it for your project. The Default Subject and Default Content fields on the project configuration page default to $DEFAULT_SUBJECT and $DEFAULT_CONTENT (respectively), delegating to the the system-wide configuration from the Extended E-mail Notification section of the Configure System page. Similarly, the per-trigger content fields default to $PROJECT_DEFAULT_SUBJECT and $PROJECT_DEFAULT_CONTENT, delegating to the project’s configuration. Since the value of a token can contain other tokens, this provides different points of configuration that can allow you to quickly make changes at the broadest level (all projects), the narrowest level (individual emails), and in-between (individual projects).

To see a list of all available email tokens and what they display, click on the "?" (question mark) associated with the Content Token Reference in the Editable Email Notification section of the project configuration page.

As of version 2.22, this plugin also supports tokens provided by the Token Macro plugin. You can see the available Token Macro Plugin Tokens below the Extended Email Publisher Specific Tokens when you click on the "?" (question mark) associated with the Content Token Reference in the Editable Email Notification section of the project configuration page.

Jelly script content templates

html
txt

New to version 2.9 is the ability to use Jelly scripts. Jelly scripts are powerful in that you can hook into the Jenkins API to get any information you want or need. Two Jelly scripts are packaged with this plugin, and it is also possible to write your own.

There are two default Jelly scripts available out of the box; one is designed for HTML emails, and the other is designed for text emails. See the screenshots below for what these templates look like. You can specify which script you want by using the template argument. The usage for each type of script is as follows:

Text-only Jelly script

${JELLY_SCRIPT,template="text"}

HTML Jelly script

${JELLY_SCRIPT,template="html"}

You can also write your own Jelly scripts. The Jelly scripts are particularly powerful since they provide a hook into the Jenkins API, including hudson.model.AbstractBuild and hudson.model.AbstractProject. For an example on how to do this, take a look at the existing html and text scripts.

Using custom Jelly scripts (those not packaged with this plugin) requires the cooperation of your Jenkins administrator. The steps are relatively simple:

  1. Create the Jelly script template. The name of the script should be <name>.jelly.

    It is important that the name ends in .jelly.
  2. Have your Jenkins administrator place the script inside ${JENKINS_HOME}/email-templates/.

  3. Use the $JELLY_SCRIPT token with the template parameter equal to your script filename without the .jelly extension. For example, if the script filename is foobar.jelly, the email content would be ${JELLY_SCRIPT,template="foobar"}.

💡
  • You can get the object of other plugin actions by querying build actions, for example:

    ${it.getAction('hudson.plugins.fitnesse.FitnesseResultsAction')}
  • Then you need to know what functions are allowed by this action object and traverse through the result.

Groovy script content templates

New to version 2.15 is the ability to use Groovy scripts. Scripts are powerful in that you can hook into the Jenkins API to get any information you want or need. There are two scripts with corresponding templates packaged with this plugin, and it is also possible to write your own.

There are two default scripts and templates available out of the box; one is designed for HTML emails and the other is design for text emails. You can specify which script you want by using the script argument; you can also leave the default script and specify a different template file using the template argument. Furthermore, you can also include a script that does some initialization using the init argument. The usage for each type of script is as follows:

Text-only Groovy script

${SCRIPT, template="groovy-text.template"}

HTML Groovy script

${SCRIPT, template="groovy-html.template"}

You can also write your own scripts and templates. The scripts are particularly powerful since they provide a hook into the Jenkins API, including hudson.model.AbstractBuild and hudson.model.AbstractProject. For an example on how to do this, take a look at the existing html and text scripts.

Using custom scripts (those not packaged with this plugin) requires the cooperation of your Jenkins administrator. The steps are relatively simple:

  1. Create the Groovy script template. The name of the script ends in the standard extension for the language (i.e., .groovy). The template can be named anything.

  2. Have your Jenkins administrator place the script inside ${JENKINS_HOME}/email-templates/.

  3. Use the $SCRIPT token with the template parameter equal to your template filename, or in addition the script parameter equal to the custom script name. For example, if the template filename is foobar.template, the email content would be ${SCRIPT, template="foobar.template"}.

Refer to the following examples for doing various things with the built-in Groovy templates:

Attachments

New to version 2.15 is the ability to add attachments using the Ant pattern matching syntax used in many places in Jenkins. You can set a maximum total attachment size in the Extended E-mail Notification section of the Configure System page; otherwise, it will be unlimited.

Jive formatter

jive-formatter.groovy contains methods for easy and convenient formatting of emails being sent from Jenkins to Jive. It should be called from the Pre-send Script area.

🔥
Jive does not appear to support text with multiple formats, so only call one formatting method per block of text.

Either formatLine or formatText can and should be called on every line of text that will be sent to the Jive system prior to calling formatting methods like color or size. Please test on your own instances of Jive and add functionality as you find it!

The following lines should be added to the Pre-send Script area prior to attempting to invoke any functions:

File sourceFile = new File("/your/preferred/path/jive-formatter.groovy");
Class groovyClass = new GroovyClassLoader(getClass().getClassLoader()).parseClass(sourceFile);
GroovyObject jiveFormatter = (GroovyObject) groovyClass.newInstance();

More Repositories

1

jenkins

Jenkins automation server
Java
21,381
star
2

docker

Docker official jenkins repo
Dockerfile
6,144
star
3

pipeline-examples

A collection of examples, tips and tricks and snippets of scripting for the Jenkins Pipeline plugin
Groovy
4,117
star
4

blueocean-plugin

Blue Ocean is a reboot of the Jenkins CI/CD User Experience
Java
2,872
star
5

configuration-as-code-plugin

Jenkins Configuration as Code Plugin
Java
2,521
star
6

kubernetes-plugin

Jenkins plugin to run dynamic agents in a Kubernetes/Docker environment
Java
2,206
star
7

job-dsl-plugin

A Groovy DSL for Jenkins Jobs - Sweeeeet!
Groovy
1,851
star
8

pipeline-plugin

Obsolete home for Pipeline plugins
1,711
star
9

JenkinsPipelineUnit

Framework for unit testing Jenkins pipelines
Groovy
1,426
star
10

gitlab-plugin

A Jenkins plugin for interfacing with GitLab
Java
1,418
star
11

jenkinsfile-runner

A command line tool to run Jenkinsfile as a function
Java
1,114
star
12

java-client-api

A Jenkins API client for Java
Java
888
star
13

jenkins-scripts

Scripts in Groovy, shell, Ruby, Python, whatever for managing/interacting with Jenkins
Groovy
880
star
14

build-monitor-plugin

Jenkins Build Monitor Plugin
Java
722
star
15

slack-plugin

A Jenkins plugin for posting notifications to a Slack channel
Java
664
star
16

git-plugin

Git repository access for Jenkins jobs
Java
660
star
17

pipeline-model-definition-plugin

Groovy
557
star
18

ghprb-plugin

github pull requests builder plugin for Jenkins
Java
495
star
19

docker-workflow-plugin

Jenkins plugin which allows building, testing, and using Docker images from Jenkins Pipeline projects.
Java
492
star
20

docker-plugin

Jenkins Cloud Plugin that uses Docker
Java
482
star
21

docker-inbound-agent

Docker image for a Jenkins agent which can connect to Jenkins using TCP or Websocket protocols
PowerShell
466
star
22

helm-charts

Jenkins helm charts
Mustache
448
star
23

pipeline-aws-plugin

Jenkins Pipeline Step Plugin for AWS
Java
423
star
24

jenkins.rb

Deprecated, see https://www.jenkins.io/jep/7
Ruby
394
star
25

generic-webhook-trigger-plugin

Can receive any HTTP request, extract any values from JSON or XML and trigger a job with those values available as variables. Works with GitHub, GitLab, Bitbucket, Jira and many more.
Java
377
star
26

dingtalk-plugin

Dingtalk for jenkins
Java
336
star
27

warnings-ng-plugin

Jenkins Warnings Plugin - Next Generation
Java
323
star
28

plugin-installation-manager-tool

Plugin Manager CLI tool for Jenkins
Java
301
star
29

mesos-plugin

Mesos Cloud Jenkins Plugin
Java
291
star
30

github-plugin

Jenkins GitHub plugin
Java
286
star
31

ec2-plugin

Jenkins ec2 plugin
Java
282
star
32

ssh-steps-plugin

Jenkins pipeline steps which provides SSH facilities such as command execution or file transfer for continuous delivery.
Java
273
star
33

ansicolor-plugin

Jenkins ANSI Color Plugin
Java
253
star
34

pipeline-utility-steps-plugin

Small, miscellaneous, cross platform utility steps for Jenkins Pipeline jobs.
Java
237
star
35

docker-agent

Base Docker image for Jenkins Agents
PowerShell
231
star
36

ansible-plugin

Jenkins Ansible plugin
Java
223
star
37

workflow-cps-global-lib-plugin

Java
223
star
38

lib-file-leak-detector

Java agent that detects file handle leak
Java
217
star
39

hashicorp-vault-plugin

Jenkins plugin to populate environment variables from secrets stored in HashiCorp's Vault.
Java
214
star
40

bitbucket-branch-source-plugin

Bitbucket Branch Source Plugin
Java
213
star
41

remoting

Jenkins Remoting module
Java
212
star
42

workflow-aggregator-plugin

211
star
43

gerrit-trigger-plugin

Java
209
star
44

android-emulator-plugin

Android Emulator plugin for Jenkins
Java
207
star
45

docker-slaves-plugin

A Jenkins plugin to run builds inside Docker containers
Java
205
star
46

pipeline-stage-view-plugin

Visualizes Jenkins pipelines
JavaScript
204
star
47

jenkinsfile-runner-github-actions

Jenkins single-shot pipeline execution in a GitHub Action POC
Shell
199
star
48

github-branch-source-plugin

GitHub Branch Source Plugin
Java
193
star
49

amazon-ecs-plugin

Amazon EC2 Container Service Plugin for Jenkins
Java
193
star
50

trilead-ssh2

Patched trilead-ssh2 used in Jenkins
Java
193
star
51

cucumber-reports-plugin

Jenkins plugin to generate cucumber-jvm reports
Java
192
star
52

docker-build-publish-plugin

Java
192
star
53

performance-plugin

Performance Test Running and Reporting for Jenkins CI
Java
188
star
54

jira-plugin

Jenkins jira plugin
Java
168
star
55

gitea-plugin

This plugin provides the Jenkins integration for Gitea.
Java
168
star
56

embeddable-build-status-plugin

Embed build status of Jenkins jobs in web pages
Java
167
star
57

stashnotifier-plugin

A Jenkins Plugin to notify Atlassian Stash|Bitbucket of build results
Java
166
star
58

docker-ssh-agent

Docker image for Jenkins agents connected over SSH
PowerShell
162
star
59

workflow-cps-plugin

Java
160
star
60

http-request-plugin

This plugin does a request to an url with some parameters.
Java
154
star
61

stapler

Stapler web framework
Java
154
star
62

kubernetes-pipeline-plugin

Kubernetes Pipeline is Jenkins plugin which extends Jenkins Pipeline to provide native support for using Kubernetes pods, secrets and volumes to perform builds
Java
154
star
63

tfs-plugin

Jenkins tfs plugin
Java
145
star
64

jep

Jenkins Enhancement Proposals
Shell
144
star
65

kubernetes-cd-plugin

A Jenkins plugin to deploy to Kubernetes cluster
Java
140
star
66

jacoco-plugin

Jenkins JaCoCo Plugin
Java
139
star
67

qy-wechat-notification-plugin

企业微信Jenkins构建通知插件
Java
138
star
68

swarm-plugin

Jenkins swarm plugin
Java
133
star
69

git-client-plugin

Git client API for Jenkins plugins
Java
130
star
70

subversion-plugin

Jenkins subversion plugin
Java
126
star
71

dependency-check-plugin

Jenkins plugin for OWASP Dependency-Check. Inspects project components for known vulnerabilities (e.g. CVEs).
Java
125
star
72

role-strategy-plugin

Jenkins Role-Strategy plugin
Java
120
star
73

groovy-sandbox

(Deprecated) Compile-time transformer to run Groovy code in a restrictive sandbox
Java
120
star
74

jenkins-design-language

Styles, assets, and React classes for Jenkins Design Language
TypeScript
116
star
75

acceptance-test-harness

Acceptance tests cases for Jenkins and its plugins based on selenium and docker.
Java
116
star
76

scm-sync-configuration-plugin

Jenkins scm-sync-configuration plugin
Java
116
star
77

gitlab-branch-source-plugin

A Jenkins Plugin for GitLab Multibranch Pipeline jobs and Folder Organization
Java
115
star
78

git-parameter-plugin

Jenkins plugin for chosing Revision / Tag before build
Java
115
star
79

publish-over-ssh-plugin

Java
114
star
80

pipeline-as-yaml-plugin

Jenkins Pipeline As Yaml Plugin
Java
114
star
81

selenium-plugin

Jenkins selenium plugin
Java
112
star
82

docker-build-step-plugin

Java
111
star
83

code-coverage-api-plugin

Deprecated Jenkins Code Coverage Plugin
Java
111
star
84

jira-trigger-plugin

Triggers a build when a certain condition is matched in JIRA
Groovy
111
star
85

cobertura-plugin

Jenkins cobertura plugin
Java
110
star
86

gradle-plugin

Jenkins gradle plugin
Java
109
star
87

credentials-plugin

Provides Jenkins with extension points to securely store, manage, and bind credentials data to other Jenkins plugins, builds, pipelines, etc.
Java
107
star
88

jira-steps-plugin

Jenkins pipeline steps for integration with JIRA.
Java
104
star
89

artifactory-plugin

Jenkins artifactory plugin
Java
104
star
90

build-flow-plugin

A plugin to manage job orchestration
Groovy
103
star
91

throttle-concurrent-builds-plugin

Java
101
star
92

github-oauth-plugin

Jenkins authentication plugin using GitHub OAuth as the source.
Java
99
star
93

pipeline-graph-view-plugin

Java
99
star
94

promoted-builds-plugin

Jenkins Promoted Builds Plugin
Java
96
star
95

ssh-slaves-plugin

SSH Build Agents Plugin for Jenkins
Java
96
star
96

github-pr-coverage-status-plugin

Nice test coverage icon for your pull requests just from Jenkins
Java
93
star
97

jenkins-test-harness

Unit test framework for Jenkins core and its plugins
Java
92
star
98

opentelemetry-plugin

Monitor and observe Jenkins with OpenTelemetry.
Java
90
star
99

localization-zh-cn-plugin

Chinese Localization for Jenkins
HTML
89
star
100

workflow-remote-loader-plugin

Load Pipeline scripts from remote locations (e.g. Git) - replaced by Pipeline: Groovy Libraries plugin
Java
88
star