Show TeamCity Buildstatus in Maven Projectsite

Today i will show you a little hack for TeamCity and Maven. At the end you will be able to show the last (live!) buildstatus of your artifact on the generate project-site.

Lets define a new menu-item “status” in our project-site-descriptor (src/site/site.xml):

  <menu name="Overview" inherit="top">
  <item name="Introduction" href="index.html" />
  <item name="Status" href="status.html" />

Hint: you can do this in your parent-project, so all subproject will inherit this menu.

Now we must define the status.xml (src/site/xdoc/status.xml):

<?xml version="1.0" encoding="UTF-8"?>
    <section name="Status">
      <div id="statuswidget"/>
    <script type="text/javascript">
      // url to the team-city-server
      // define HOST, PORT and BUILDID
      var url = 'http://HOST:PORT/externalStatus.html'
               + '?buildTypeId=BUILDID'
               + unescape( '%26' )   // "hide" amp
               + 'withCss=true';
      var container = document.getElementById('statuswidget');
      var iframe = document.createElement('iframe');  = '100%'; = '500px'; = 'none';
      iframe.doc = null;
        iframe.doc = iframe.contentDocument;
      else if(iframe.contentWindow)
        iframe.doc = iframe.contentWindow.document;
      else if(iframe.document)
        iframe.doc = iframe.document;;

Insert HOST and PORT. The BUILDID is the number of the build-configuration:

Hint: The width of the iframe should be 100% but you can customize the height – so if you later click on the status-element you can show teamcity directly in you projectsite … cool :D

Activate the status-widget for your build-configuration:

Build the site:

mvn clean site-deploy

Now you have a new menu-item, click and you will see the TeamCity status for your artifact.

The implementation details …

The “normal” way to display the build-status (see TeamCity documentation) is shown here:

<script type="text/javascript" src="<path_to_server>/externalStatus.html?js=1&amp;amp;buildTypeId=BUILDID">

But it’s not possible to insert this code in maven’s xdoc-format (there is no javascript-tag allowed!).
So i found a solution to insert the teamcity-url into a dynamic created iframe. The second trick is to encode the “&” in the url (unescape(‘%26’)).

Try it!