Sumitk
Sumitk

Reputation: 1505

Send Jenkins console output as HTML email

I don't know if this is at all possible but still asking here to see if anyone has tried/thought about it.

I have a build running that when fails echo out html code as given below. I want to send this html as an email to all the recipients.

Currently when I use the simple email plugin then the whole console output is sent as an email which contains all these html tags (not at all readable). Then I installed the Email Ext plugin but I am not sure if the pre-send script can read my console output and send email. Has anyone tried it? Is it worth spending time on it or should I just modify the output to display formatted text?

This build is for internal tools and I can't create a .html file or send the link to the .html file as email because the path is behind firewall.

I don't know if this is supported at all but is it possible that the console output shows 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>

Upvotes: 18

Views: 38611

Answers (5)

Robert
Robert

Reputation: 1631

Even if you are behind a firewall, you should be able to write an HTML file to the workspace (from your script). This file you can then send as/include in the mail body using ${FILE,path="PATH"}.

Upvotes: 0

Ajeet Khan
Ajeet Khan

Reputation: 9190

Go to "Manage-jenkins"->"configure system" Than on the "Extended E-mail Notification" settings, put the below line in "default content" text-area

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

Upvotes: 7

Sumitk
Sumitk

Reputation: 1505

So this is how I solved it with the help of @Slav.

Jenkins job was running 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 job was configured with email-ext and in the Add post-build action->Editable Email Notification -> Default Content I put the following:

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

This send the email as html content and not the text of html.

Upvotes: 7

Slav
Slav

Reputation: 27485

Email Ext plugin works just fine with HTML. It's up to your email client to parse HTML (but then again, most these days do).

The question is: how does your build output this HTML above? Does it output it to file? Does it display it in Console Output?

If the text is in console output, use:

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

The <pre> tags are to preserve spacing/formatting.
The start and end regular expressions are to identify the "starting line" from which to start displaying log, and the "ending line" at which to stop displaying log.

Note that the start and end lines themselves are excluded. So, in your build, put a header and footer lines just before and just after your html output, and use them here.

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

Upvotes: 20

Devesh
Devesh

Reputation: 866

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

Upvotes: 1

Related Questions