How to embed html report in email body using Email-ext plugin?


How do I email a html report generated in a job build (located in workspace) in an email notification?

I also want to ensure that the html report is embedded in the email body.



In Post-build actions - Editable Email Notification

  • Ensure Content Type is set to html.
  • In Default Content add ${FILE,path="my.html"}. Replace my.html with your html file. Path is workspace relative.

Alternatively, if you are interested in embedding an html file in an email’s body using a pipeline, you can use as a reference the contents of stage('Email') listed below. The stage('Writing html file') has been included in the example for completeness. It is used to generate a simple html file and give you the opportunity of testing the code snippet as is.

node {
        stage('Writing html file')
        sh 'echo "<html>" >> myfile.html'
        sh 'echo "<header><title> This is the title</title></header>" >> myfile.html'
        sh 'echo "<body> how do you do? </body>" >> myfile.html'
        sh 'echo "</html>" >> myfile.html'
        sh 'ls -al myfile.html'
        sh 'head -1 myfile.html'
        env.ForEmailPlugin = env.WORKSPACE
        emailext mimeType: 'text/html',
        body: '${FILE, path="myfile.html"}',
        subject: currentBuild.currentResult + " : " + env.JOB_NAME,
        to: ''

Have more questions?


  • 1
    Tanu Muk2009

    Doesn't work. It does embed in the body of the email, but the css ad html files aren't embedded! Looks so unfinished! 

  • 0
    Rakesh Adupa

    Same here. did You find solution for that

  • 0
    Cassandra Rodriguez

    similar - this worked for me though:


    1. Add this to build: execute shell section:

    echo count=$count > count.txt
    echo distinctcount=$distinctcount > distinctcount.txt

    2. Add this to Inject Environmental Variables section under "Properties File Path:





    (note: workspace is pwd for jenkins and lists the location)


    3. Call the variable in the "default content" section of "editable email notification":

    Count total:$count Distinct Count: $distinctcount



    Be sure you have email setup as "always" under "advanced settings" at the bottom of the email settings, otherwise it only emails upon first success or any faillure:

    Edited by Cassandra Rodriguez
  • 0
    David David

    question: when using a scripted pipeline, with the 'emailext' how do properly format the body of the email ?

    Typically I define my own content/body with mimeType : 'text/html'

    The body I put together using different kinds of data from my job. Here I use "<br>" as separator, which works will for items I add myself. But when adding stuff like '${BUILD_LOG}'   (giving the truncated build log,
    no (html) newlines are inserted.
    I have even tried to replace '\n' by '<br>\n' like:

       def emailLog = '${BUILD_LOG}'.replace('\n','<br>\n')

    but that does not seem to have effect. I am guessing the that BUILD_LOG is only evaluated within the emailext plugin, so after my replace. How to achieve a replacement. Or better way of proper formatting?? 
    Note: I could go for using a template, but that is a bridge too far right now ...

    thx, M



Please sign in to leave a comment.