9

I am using Jenkins and email-ext to send build notifications. Build produces small custom report stored as simple HTML in out directory. Right now I can easy attach this report to the email, but what I want is to have this report rendered to the email body itself. I know that I can write my own jelly template, but this requires access to the build server(to install jelly script), I want to avoid this too. So my questions are:

  1. Can I include content of the arbitrary file(generated during build) to Content field of the Email-Ext plugin?
  2. If I cannot, what is most easy way to send such report in Jenkins?
Mike Chaliy
  • 25,801
  • 18
  • 67
  • 105
  • possible duplicate of [Load HTML File Contents to Div \[without the use of iframes\]](http://stackoverflow.com/questions/3535055/load-html-file-contents-to-div-without-the-use-of-iframes) – Ankur Agarwal Apr 30 '15 at 23:15

3 Answers3

14

It looks like most easy way is to use 'Pre-send Script' of the Email-ext

Script looks like this:

def reportPath = build.getWorkspace().child("HealthTestResults.html")
msg.setContent(reportPath.readToString(), "text/html");

It renders content of the HealthTestResults.html located in the root of the workspace just as body of the message.

Mike Chaliy
  • 25,801
  • 18
  • 67
  • 105
  • Is there a way to run a script in build.getWorkspace()? I'd like to process TEST*.xml files. – Noel Yap Sep 03 '13 at 23:58
  • @Noel Yap - Your best method for processing XML files to HTML is to add an XSL process to your build. And then include the the output as the inline attachment (see above). – Ramon May 19 '14 at 15:22
  • This code is working for me , but now my problem is , there is one attachment (specified in "Attachments" section of the plugin ) which is missing – Hashim MH May 12 '15 at 05:59
5

Easy way to include the html file to email content is to add below line in the default content = ${FILE, path="yourfilename.html"}

this works for me in jenkins email ext plugin

Chetan Kabra
  • 353
  • 5
  • 10
0

If you use groovy template, then you can do something like this

stage("Notifications") {
            steps {
                script {
                    env.ForEmailPlugin = env.WORKSPACE

                    emailext mimeType: "text/html",
                        body: '''${SCRIPT, template="notification.template"}''',
                        subject: env.JENKINS_PROJECT + " " + currentBuild.currentResult + " : " + env.JOB_NAME + "/" + env.GIT_COMMIT,
                        recipientProviders: [requestor(), developers()],
                        from: env.JENKINS_EMAIL,
                        attachLog: true
                }
            }
        }

and slice of /var/lib/jenkins/email-templates/notification.template

<!-- ARGOCD SYNC OUTPUT -->
<h3>ArgoCD<h3/>
<hr size="1" />
<tt>
${new File("/tmp/sync.txt").text.replaceAll('\n','<br>').replaceAll(' ', '&nbsp;')}
</tt>
DmitrySemenov
  • 9,204
  • 15
  • 76
  • 121