Send Jenkins console output as HTML email

I do not know if this is possible, but I still ask to find out if anyone has tried this.

I have an assembly that works when the html echo cannot be executed as follows. I want to send this html as an email to all recipients.

Currently, when I use a simple email plugin, all console output is sent as an email containing all of these html tags (not readable at all). Then I installed the Ext email plugin, but I'm not sure if the pre-send script can read my console output and send email. Has anyone tried it? Is it worth it to spend time on this or do I just need to change the output to display formatted text?

This assembly is for internal tools, and I cannot create the .html file or send the link to the .html file as email, because the path is behind the firewall.

I don't know if this is supported at all, but is it possible that the output to the console displays the html output?

Thanks for the help!

<style type="text/css"> table.gridtable { font-family: verdana,arial,sans-serif; font-size:11px; color:#333333; border-width: 1px; border-color: #666666; border-collapse: collapse; } table.gridtable th { border-width: 1px; padding: 8px; border-style: solid; border-color: #666666; background-color: #dedede; } table.gridtable td { border-width: 1px; padding: 8px; border-style: solid; border-color: #666666; background-color: #ffffff; } </style> <table class="gridtable"> <thead> <tr> <th>Service Checked</th> <th>Status</th> <th>Response</th> </tr> </thead> <tbody> <tr> <td>canary</td> <td>Success</td> <td>Please override the check() method</td> </tr> <tr> <td style="color: red;"><strong>www.mysite.com</strong></td> <td style="color: red;">Failure</td> <td>Ping to https://www.mysite.com/canary?from=here FAILED</td> </tr></tbody></table> 
+6
source share
4 answers

Email Ext plugin works great with HTML. This is for your email client to parse HTML (but again, in most cases).

Question: How does your assembly output this HTML above? Does it output it to a file? Does this display it in console output?

If the text is displayed on the console, use:

<pre>${BUILD_LOG_EXCERPT, start="Regex-for-start", end="Regex-for-end"}</pre>

<pre> tags must preserve spacing / formatting.
The regular expressions start and end must identify the "start line" from which to start displaying the log, and the "end line" in which the log display stops.

Note that the start and end strings themselves are excluded. So, in your assembly, place the header and footer lines immediately before and immediately after the html output and use them here.

For reference, in the ext-email configuration, click the Content Reference ? Icon icon

+9
source

So this is how I solved it with @Slav .

Jenkins work executed this script:

 <?php echo "start-here\n"; echo "<html><body><table border=1> <tr><td>yello1111</td><td>11111bbbbbbb</td></tr> <tr><td>yelloooo</td><td>bbbbbbb</td></tr> </table></body></html>"; echo "end-here\n"; 

The task was configured using email-ext and in Add post-build action-> Editable Email Notification → Default Content I added the following:

 ${BUILD_LOG_EXCERPT, start="\\b(start-here)\\b", end="\\b(end-here)\\b"} 

This will send the email as html content, not html text.

+4
source

The email-ext plugin works very well for me. Give it a try.

+1
source

Go to "Manage-jenkins" → "configure the system" Then in the settings "Advanced email notification" put the bottom line in the text field "by default"

 <pre>${BUILD_LOG, maxLines=9999, escapeHtml=false}</pre> 
+1
source

Source: https://habr.com/ru/post/979420/


All Articles