5

I am new to Jenkins and I'm trying to attach a HTML file to the body of an email that is created on one of my slaves. I'm using the email-ext plugin but I'm not sure how to attach the HTML to the body - i.e. where does the HTML file have to be located, code to attach it?

Praetorian
  • 106,671
  • 19
  • 240
  • 328
erman8
  • 2,141
  • 3
  • 19
  • 17

4 Answers4

5

I would suggest also just plugging your HTML code straight into the email trigger section.

heres an example of what i'm using:

<html>
<body>
Hi there $DOTCI_PUSHER
<br>
<br>
You are receiving this email because Build $BUILD_NUMBER has been set to: $BUILD_STATUS
<br>
<br>
<u>Execution Results :</u><br>
Avg : ${BUILD_LOG_REGEX, regex="Avg:", showTruncatedLines=false}<br>
Min : ${BUILD_LOG_REGEX, regex="Min:", showTruncatedLines=false}<br>
Max : ${BUILD_LOG_REGEX, regex="Max:", showTruncatedLines=false}<br>
Errors : ${BUILD_LOG_REGEX, regex="Err:", showTruncatedLines=false}<br>
<br>
Build URL : $BUILD_URL
<br>
<br>
Console Output: <br>
<pre>${BUILD_LOG, maxLines=20}</pre>
</body>
</html>
Jordan
  • 387
  • 1
  • 4
  • 9
  • This is a good suggestion and it served as a good starting point for me to explore more. There is a lot more where BUILD_LOG_REGEX came from, which is token-macro plugin. Documentation is poor, so refer to: https://github.com/jenkinsci/token-macro-plugin/tree/master/src/main/java/org/jenkinsci/plugins/tokenmacro/impl and https://github.com/jenkinsci/token-macro-plugin/tree/f74697a6e54087f9334eef153948ba85f33fe596/src/main/resources/org/jenkinsci/plugins/tokenmacro/impl). Also refer: https://github.com/jenkinsci/email-ext-plugin/tree/master/src/main/java/hudson/plugins/emailext/plugins/content – haridsv Jan 06 '20 at 17:04
3

I'm pretty sure someone here can come up with a more fancy solution, but I've seen (not been able to get it to work as I would like :-( ) that this can be done using a groovy template.

It should be as simple as placing the following snippet inside the body of your e-mail content:${SCRIPT, template="groovy-html.template"}

And then modifying the content of the groovy-html.template file to suit your needs. I'd recommend starting out with the template already present with your installation and then modifying it as you go along.

You might also need to include the groovy plugin but I'm not sure about that.

llykke
  • 253
  • 2
  • 14
2

See this answer: Display HTML page inside mail body with Email-ext plugin in Jenkins

You should add the absolute path of your html file, or it's relative path to workspace, like:

${FILE,path="test-output/html/index.html"}
Community
  • 1
  • 1
Noam Manos
  • 15,216
  • 3
  • 86
  • 85
0

You should be able to put your html code in the content box in the email trigger section. Maybe not full html but it support basic syntax like
As email-ext support Token Macro plusgin, You can use the macros like ${BUILD_URL} to add personalized content into the email.

Lucas
  • 75
  • 8