Modifying emails sent using CruiseControl.NET's email publisher

Last year I wrote a brief post on configuring email for CCNET whereas this time I’m looking at changing the content of mail sent by the email publisher. Btw, modifying the email is identical to controlling the look of the web dashboard so this really covers both topics. The first thing to note is that the format of the email is specified in ccnet.exe.config (or ccservice.exe.config) as follows:

<!-- Specifies the stylesheets that are used to transform the build results when using the EmailPublisher -->
<xslFiles>
    <file name="xsl\header.xsl"/>
    <file name="xsl\compile.xsl"/>
    <file name="xsl\unittests.xsl"/>
    <file name="xsl\fit.xsl"/>
    <file name="xsl\modifications.xsl"/>
    <file name="xsl\fxcop-summary.xsl"/>
</xslFiles>

The above collection of XSL files (included, by default, with CCNET) are used to construct the email body in the order they’re listed. To change the layout or add/remove content you can either edit the above .xsl files or add your own to augment the output as you see fit. The down side is you’ll need at least some understanding of XSL to make those changes.

In the case of my EDI work with CCNET I want to publish error details from custom CCNET tasks using the email publisher. By modifying the email content I can include details such as what caused the build to fail. When these custom tasks execute they contribute XML to the build log which looks similar to the following:

<editask warning_count="0" error_count="2">
  <files>
    <error name="c:\edi\partners\inbound\P100451612.850.TXT" message="Invalid buyer or buyer not configured to allow EDI DUNS: 00xxxxxx9" />
    <error name="c:\edi\partners\inbound\SYSCO850.txt" message="Invalid buyer or buyer not configured to allow EDI DUNS: 8xxxxxxx7" />
  </files>
</editask>

To have this content included in the email I modified msbuild2ccnet.xsl which is a stylesheet from Christian Rodemeyer to parse MSBuild output (available here), and tweaked it to handle the above XML. I then added <file name=”xsl\edi.xsl”/> to the above <xslfiles> section. When the build fails this content is included in the email that’s published. Btw, making the same change to dashboard.config and copying the .xsl file to the webdashboard\xsl folder will update the CCNET web dashboard.

2 thoughts on “Modifying emails sent using CruiseControl.NET's email publisher

  1. Hello, sorry if I wrote here…
    but I need an support
    Using Cruisecontrol, I want received the email when the build is failed or success that contains directly the results and not the url to show them.
    Another think is it possible to schedule a build only when one file is modified .Could you help me?
    Below my configure.xml file:
    <currentbuildstatuslistener file="logs/${project.name}/status.txt"/>
    </listeners>
    <bootstrappers>
    <antbootstrapper anthome="apache-ant-1.7.0" buildfile="projects/${project.name}/build.xml" target="clean" />
    </bootstrappers>
    <modificationset quietperiod="10">
    <svn localWorkingCopy="projects/${project.name}" />
    </modificationset>
    <schedule interval="300">
    <ant anthome="apache-ant-1.7.0" buildfile="projects/${project.name}/build.xml"/>
    </schedule>
    <log dir="logs/${project.name}">
    <merge dir="projects/${project.name}/target/test-results"/>
    </log>
    <publishers>
    <currentbuildstatuspublisher
    file="logs/${project.name}/buildstatus.txt"/>
    <gforge projectId="19"
    cruisecontrolId="2"
    hash="b1CHfgMz4YSvPfSQKe8j6XutFy0="
    />
    <onsuccess>
    <artifactspublisher dest="artifacts/${project.name}" file="projects/${project.name}/target/${project.name}.jar"/>
    </onsuccess>
    <email mailhost="smtp.spaziozerouno.it" includeDetails="TRUE"
    returnaddress="cruisecontrol@spaziozerouno.it"
    buildresultsurl="http://192.168.247.12:8080/cruisecontrol/buildresults/cm-dg&quot;
    skipusers="true" spamwhilebroken="true">
    <always address="maurizio.iannarelli@spaziozerouno.it"/>
    <failure address="costanza.pastore@spaziozerouno.it" reportWhenFixed="true"/>
    </email>
    </publishers>
    </project>
    </cruisecontrol>

Comments are closed.