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' } }