Issue
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.
Resolution
In Post-build actions - Editable Email Notification
-
Ensure Content Type is set to html.
-
In Default Content add
${FILE,path="my.html"}
. Replacemy.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' } stage('Email') { env.ForEmailPlugin = env.WORKSPACE emailext mimeType: 'text/html', body: '${FILE, path="myfile.html"}', subject: currentBuild.currentResult + " : " + env.JOB_NAME, to: 'example@example.com' } }
This article is part of our Knowledge Base and is provided for guidance-based purposes only. The solutions or workarounds described here are not officially supported by CloudBees and may not be applicable in all environments. Use at your own discretion, and test changes in a safe environment before applying them to production systems.