Dashboard > CruiseControl > Home > UnitTestEmailPublisher
UnitTestEmailPublisher Log In | Sign Up   View a printable version of the current page.

Added by Bryce Hendrix , last edited by Bryce Hendrix on Apr 19, 2006  (view change)
Labels: 
(None)

Sometimes you may want to send someone other than the CC admin email if something goes wrong with the build. I wrote a an extensible email publisher which sends email to a list of recipients based on rules specified in the CC config file. We use it for sending email upon unit test failures, although it could be easily adapted to anything thats reported in the CC build log.

The UnitBlame class extends the CC HTMLEmailPublisher. It parses the CC build log looking for "testcase" elements (remember we use it for unit tests). For each error/failure, it generates a result object, then calls the blame rule (any class implementing IBlameRule), which returns a list of recipients. The results object is then used to generate an email, which is sent to every recipient.

This publisher could be easily generalized by moving the unit test related code, which is in UnitBlame.buildBrokenResult(), and UnitBlame.parseResultsFile(), to a separate class/interface.

For those interested in using this to send email to everyone who has subbmitted code in the case of a build failure, I would recommend one of two approaches:

  1. change parseResultsFile() to use the XmlLogHelper object's getModifications() method and iterate over each of the modifications calling your blame rule on it to get the recipient list.
  2. changing the parseResultsFile() method to search for the "modification" elements in the CC build log, passing each to buildBrokenResult() to parse & fill the results object. Your blame rule should probably be something simple like just mapping users to email addresses.

I've included one example of a blame rule we use to send email to all of the users that committed code in a unit test's parent dir if a unit test fails. To compile the example class you'll need javasvn

Powered by a free Atlassian Confluence Open Source Project / Non-profit License granted to ThoughtWorks, Inc.. Evaluate Confluence today.
Powered by Atlassian Confluence 2.7.1, the Enterprise Wiki. Bug/feature request - Atlassian news - Contact administrators