-
Notifications
You must be signed in to change notification settings - Fork 9
Emailing Results
Sometimes, an effective way of monitoring the results of a test involve emailing those results upon test completion. You can find an example of how this can be done in the Ansible Engine Test, and I will summarize the essentials below.
The first thing to do to begin working with email is to ensure that the email-ext plugin installed. You can do this by going to your Jenkins, navigating to Manage Jenkins > Manage Plugins > Installed
and search for Email Extension Plugin
.
Once you've confirmed that is present, you need to configure it. You can do this by going to Manage Jenkins > Configure System
and scrolling down to Extended E-mail Notification
.
Here, the two most important things to set are the SMTP server
and the Default user E-mail suffix
.
Should be set to something like smpt.example.com
.
Should be set to something like @example.com
.
Feel feel to look through and fill out any other default values you may deem relevant.
Finally, hit Save
or Apply
to ensure your changes are made permanent.
The key edits that need to be made to the test template are that recipients list should be added as a parameter, and that a call to the emailext
step should be made. These are described in further detail below.
This is an optional addition since your recipient list may be fixed. It's useful, however, at times where you may want to add individuals for specifics builds or to turn off emails for a test build by overriding it to a blank list of recipients.
string(
defaultValue: '',
description: 'Semi-colon delimited list of email notification recipients.',
name: 'EMAIL_SUBSCRIBERS'
)
First, you want to build strings that will encapsulate the subject and body of your email. Once that is done, you can send an email by simply calling the emailext build step with the parameters listed below.
def emailBody = "Results for ${env.JOB_NAME} - Build #${currentBuild.number}\n\nResult: ${currentBuild.currentResult}\nURL: $BUILD_URL"
if (errorMessages) emailBody += "\nErrors: " + errorMessages
emailext(
subject: "${env.JOB_NAME} - Build #${currentBuild.number} - ${currentBuild.currentResult}",
body: emailBody,
from: 'multiarch-qe-jenkins',
replyTo: 'multiarch-qe',
to: "${params.EMAIL_SUBSCRIBERS}",
attachmentsPattern: 'artifacts/tests/**/**/artifacts/**/*.*'
)
Here are the key parameters to sending an email. A full list is available in the Jenkins Pipeline Reference docs.
The subject of your email.
The body of your email.
The sender of the email as it appears when received.
The email address that recipients should direct their responses to.
The list of recipients.
Specifies the path to the files that should be attached. Uses ant-glob syntax.