Skip to content
This repository has been archived by the owner on Sep 18, 2021. It is now read-only.

Emailing Results

Jeremy Poulin edited this page Nov 29, 2018 · 3 revisions

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 Email-Ext Plugin

Updating the Test Template

Subscriber's Parameter

string(
    defaultValue: '',
    description: 'Semi-colon delimited list of email notification recipients.',
    name: 'EMAIL_SUBSCRIBERS'
)

Performing the Email

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/**/*.*'
    )

Parameters

subject

The subject of your email.

body

The body of your email.

from

The sender of the email as it appears when received.

replyTo

The email address that recipients should direct their responses to.

to

The list of recipients.

attachmentsPattern

Specifies the path to the files that should be attached. Uses ant-glob syntax.