Automatic Email — Jenkins Results in HTML Table
Configure a Jenkins job with Execute Groovy script as a build step and copy the below groovy script.
Join the DZone community and get the full member experience.Join For Free
We often have a requirement to send all consolidated test results of nightly runs (with more than one job configured for test executions) to the team in an easily readable email.
This document outlines the process of achieving the same with a groovy script that used markup language to implement HMTL styles and Extended E-mail Notification plugin to automatically send email notifications.
In the below example, all the test results of the Jenkins jobs are pushed to a time-based database and the latest run results are extracted to a JSON format using rest API.
Configure a Jenkins job with Execute Groovy script as a build step and copy the below groovy script. This script takes regressiontestresults.json which is a JSON file, created from the API response with the latest test results of all the test executions and converts into HTML.
The created HTML file from the groovy script (regressiontestresults.html) should be given as an input to Extended E-mail Notification.
Email received/Output: When the job is executed successfully we will receive an email in the below format.
Sample JSON file snippet, regressiontestresults.json which is given to the groovy file as input.
- This job can be configured as a downstream project of your nightly regression jobs or it can also schedule this job to send the test results in a formatted email at regular intervals of time
- Configuring Extended E-mail Notification plugin is outlined here
- Clear the folder where the results are stored in a pre-build step
- The below plugin versions for the above solution are tested on Jenkins 2.121.3
Extended-Email Notification: 2.6.6
Opinions expressed by DZone contributors are their own.