Custom email with Hudson continuous integration

If you are using continuous integration for your project, you are cool. If you are using Hudson, you are uber cool. Anyways, regardless of the continuous integration (CI) tool you are using, sending emails via it is very useful. Hudson, certainly has a default Email Notification system. I was excited to see this feature, but once I saw the default email content, I was like, mmhhe!, this needs some revamp. There is a plugin available for custom email notification, http://wiki.hudson-ci.org/display/HUDSON/Email-ext+plugin. This plugin allows us to send HTML content in the email. Now we are talking. You would find tons of links in the cloud on how to setup this plugin to get things started. But, in my experience, the requirements for the contents of the email, its format etc. varies from team to team. Just to put be a little helpful here, below is the HTML content of the email I am using for a test project of mine,

<div class="panelMacro">
<table>
<tbody>
<tr>
<td class="noteMacro">
Hudson project, <a
href="${PROJECT_URL}">${PROJECT_NAME}</a>, is <b>${BUILD_STATUS}</b> for
build number <a href="${BUILD_URL}">${BUILD_NUMBER}</a>
</td>
</tr>
<tr>
<td class="infoMacro">
Build cause: ${CAUSE}
</td>
</tr>
<tr></tr>
<tr>
<td>
<div><b>Changes</b></div>
<br />
<div class="changesList">${CHANGES, showPaths=true, format="<div><b>[%a]</b> - %p</div><br />"}</div>
</td>
</tr>
<tr>
<td>
<div><b>Build Log</b></div>
<br />
<div style="font-size:13px;">${BUILD_LOG_REGEX, regex="Build FAILED*", linesAfter=100}</div>
</td>
</tr>
</tbody>
</table>
</div>


I have not included the stylesheet content used by this html. I have included the following things in the email,




  • Project url, project name, build status and build url. These links obviously are not accessible if you are seeing this email outside your company network.

  • Build cause says whether the build was triggered due to an SCM change, started manually by a user etc.

  • Change list, displays a list of commits done since the last change. Each entry shows the user committing the change, and the name of the file checked in.

  • Build log, shows the end of the log in case of a failure. This helps in knowing what were the build errors which caused the build failure. It is kind of important if you are not able to see the Console output as you are outside the company network and not able to access Hudson url. The way this works is, by doing a regex match on the “Build Failed” text in the Console output.


This is just a sample of how you could make your email notification really useful even when you or your team is not able to access Hudson dashboard.

1 Comment:

samba said...

Hi,

How can i use this html content in my hudson?

Post a Comment