DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • How To Approach Java, Databases, and SQL [Video]
  • How To Send SQL Server CPU Utilization Alerts Using SQL Server Agent
  • Virtual Reality and Augmented Reality in the Browser
  • Embed a Spreadsheet Into Your Web App

Trending

  • Taming Parameter Sniffing in SQL Server 2022 With PSP Optimization
  • PWA on iOS, Part 2: HTTPS, Manifest and Service Worker
  • Data Integration Landscape 2026: Event Streaming, API, and Batch in the Era of Agentic AI
  • PostgreSQL vs Oracle: When Higher Cost Means Better Performance

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Data Engineering
  3. Databases
  4. Automatic Email — Jenkins Results in HTML Table

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.

By 
Manasa Malla
·
Apr. 24, 20 · Analysis
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
24.3K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

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. 

Groovy
 




x
1
80


 
1
import groovy.json.JsonSlurper
2
import groovy.json.JsonSlurper
3
 
          
4
def inputFile = new File("C:\\IX\\jenkins\\service\\results\\regressiontestresults.json")
5
def InputJSON = new JsonSlurper().parseText(inputFile.text)
6
def writer = new StringWriter() // html is written here by markup builder
7
def markup = new groovy.xml.MarkupBuilder(writer) // the builder
8
 
          
9
String id1 = InputJSON.get("Results")
10
def id2 = InputJSON.get("Results")
11
 
          
12
markup.html {
13
  head {
14
   style(type: "text/css", ''
15
    '
16
    .failedtest {
17
     color: red;
18
     text - align: center;
19
    }
20
    ''
21
    ')
22
   }
23
   markup.body {
24
 
          
25
    p "Hi All,"
26
 
          
27
    p "Please analyze the failures and add your analysis in the remarks column."
28
 
          
29
    p "Note: This is the first version of the automatic email, we shall keep enhancing the format for automatic color coding and grouping of data."
30
 
          
31
   } {
32
    markup.table(border: "1") {
33
     markup.thead(bgcolor: "blue") {
34
      markup.tr {
35
       markup.th("Team")
36
       markup.th("Profiles")
37
       markup.th("FrameWork")
38
       markup.th("Total Tests")
39
       markup.th("Passed")
40
       markup.th("Failed")
41
       markup.th("Skipped")
42
       markup.th("Results URL")
43
       markup.th("Date")
44
       markup.th("Remarks")
45
      } // tr
46
     } // thead
47
 
          
48
     def dateinhtml
49
     def teamName
50
     markup.tbody {
51
      markup.tr {
52
       for (def data: id2) {
53
        markup.tr {
54
         teamName = data.pyTextValue.toString()
55
         markup.td(align: "left", teamName.substring(1, teamName.length() - 1))
56
         markup.td(align: "left", data.Profile)
57
         markup.td(align: "left", data.ToolRunner)
58
         markup.td(align: "center", data.TotalTests)
59
         markup.td(align: "center", data.Passed)
60
         if (data.Failed.toInteger() == 0) {
61
          markup.td(align: "center", data.Failed)
62
         } else {
63
          markup.td('class': 'failedtest', data.Failed)
64
         }
65
 
          
66
         markup.td(align: "center", data.Skipped)
67
         markup.td(align: "left", data.ResultsURL)
68
         //  markup.td(align:"right",data.DateTime)
69
         dateinhtml = data.DateTimeValue.toString()
70
         markup.td(align: "right", dateinhtml.substring(1, 11))
71
 
          
72
        } // foreach
73
       } // td
74
      } // tr
75
     } //tbody
76
    } // table
77
   }
78
 
          
79
   def newFile = new File("C://IX//jenkins//service//results//regressiontestresults.html")
80
   newFile.write(writer.toString())



The created HTML file from the groovy script (regressiontestresults.html) should be given as an input to Extended E-mail Notification.

email notifications

Email received/Output: When the job is executed successfully we will receive an email in the below format.

Email received/Output

Sample JSON file snippet, regressiontestresults.json which is given to the groovy file as input.

JSON file snippet

Recommendations:

  1. 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
  2. Configuring Extended E-mail Notification plugin is outlined here
  3. Clear the folder where the results are stored in a pre-build step
  4. The below plugin versions for the above solution are tested on Jenkins 2.121.3
    • Groovy: 2.5.5
    • Extended-Email Notification: 2.6.6
HTML Jenkins (software) Database

Opinions expressed by DZone contributors are their own.

Related

  • How To Approach Java, Databases, and SQL [Video]
  • How To Send SQL Server CPU Utilization Alerts Using SQL Server Agent
  • Virtual Reality and Augmented Reality in the Browser
  • Embed a Spreadsheet Into Your Web App

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook