Thursday, April 3, 2008

Show your CC.NET dashboard in Sharepoint

I was wondering today if it's possible to get the webdashboard for CruiseControl.NET in Sharepoint. I didn't want to use an html scrapper, so I thought the XML webpart should be a good start. I needed the server status as XML, but found no reference in the helpfiles of CC.Net. On the other hand, Thoughtworks does have a page with information about a xml format for CI build status.
After inspecting the CCTray application and the logfiles on my server, I finally found the undocumented URL for this XML document with the status: http://buildserver.local/XmlServerReport.aspx.
After this quest for XML, I only needed an XSLT to get the results. So here it is:

<?xml version="1.0" encoding="utf-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:output method="xml" encoding="utf-8" indent="yes" omit-xml-declaration="yes" />

  <xsl:template match="/">

    <table border="0" cellpadding="0" cellspacing="0">

      <thead>

        <th style="text-align:left;">Project</th>

        <th>&#160;</th>

        <th style="text-align:left;">Status</th>

        <th>&#160;</th>

        <th style="text-align:left;">Last buildtime</th>

        <th>&#160;</th>

        <th style="text-align:left;">Buildlabel</th>

        <th>&#160;</th>

        <th style="text-align:left;">Activity</th>

      </thead>

      <tbody>

        <xsl:apply-templates select="/CruiseControl/Projects/Project"/>

      </tbody>

    </table>

  </xsl:template>

 

  <xsl:template match="Project">

    <tr>

      <td class="ms-vb" align="top" nowrap="nowrap">

        <xsl:element name="a">

          <xsl:attribute name="onfocus">OnLink(this)</xsl:attribute>

          <xsl:attribute name="href">

            <xsl:value-of select="@webUrl"/>

          </xsl:attribute>

          <xsl:attribute name="onclick">GoToLink(this);return false;</xsl:attribute>

          <xsl:attribute name="target">_self</xsl:attribute>

          <xsl:value-of select="@name"/>

        </xsl:element>

      </td>

      <td>&#160;</td>

      <xsl:element name="td">

        <xsl:attribute name="class">ms-vb</xsl:attribute>

        <xsl:attribute name="align">top</xsl:attribute>

        <xsl:attribute name="style">

          padding-bottom: 3px;

          <xsl:choose>

            <xsl:when test="@lastBuildStatus='Failed'">

              color:red;

            </xsl:when>

            <xsl:when test="@lastBuildStatus='Exception'">

              color:red;

            </xsl:when>

            <xsl:when test="@lastBuildStatus='Unknown'">

              color:yellow;

            </xsl:when>

            <xsl:when test="@lastBuildStatus='Failed'">

              color:red;

            </xsl:when>

            <xsl:otherwise>

              color:green;

            </xsl:otherwise>

          </xsl:choose>

        </xsl:attribute>

        <xsl:value-of select="@lastBuildStatus"/>

      </xsl:element>

      <td>&#160;</td>

      <td class="ms-vb" style="padding-bottom: 3px;" align="top">

        <xsl:value-of select="substring-before(@lastBuildTime,'T')"/>&#160;

        <xsl:value-of select="substring-before(substring-after(@lastBuildTime,'T'),'.')"/>

      </td>

      <td>&#160;</td>

      <td class="ms-vb" style="padding-bottom: 3px;text-align:right;" align="top">

        <xsl:value-of select="@lastBuildLabel"/>

      </td>

      <td>&#160;</td>

      <xsl:element name="td">

        <xsl:attribute name="class">ms-vb</xsl:attribute>

        <xsl:attribute name="align">top</xsl:attribute>

        <xsl:attribute name="style">

          padding-bottom: 3px;

          <xsl:choose>

            <xsl:when test="@activity='Building'">

              color:red;

            </xsl:when>

            <xsl:when test="@activity='CheckingModifications'">

              color:yellow;

            </xsl:when>

            <xsl:otherwise></xsl:otherwise>

          </xsl:choose>

        </xsl:attribute>

        <xsl:value-of select="@activity"/>

      </xsl:element>

    </tr>

  </xsl:template>

</xsl:stylesheet>

 



Now you need only to configure a custom XML Webpart to load the xml from your buildserver, set the XSLT and the title of the webpart.