Archive

Posts Tagged ‘Build’

Show TeamCity Buildstatus in Maven Projectsite

Wednesday, 20. August 2008 Comments off

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" />
  </menu>
 ...

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"?>
<document>
  <properties>
    <title>Buildstatus</title>
  </properties>
  <body>
    <section name="Status">
      <div id="statuswidget"/>
    </section>
    <script type="text/javascript">
    <![CDATA[
      //
      // 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');
      iframe.style.width  = '100%';
      iframe.style.height = '500px';
      iframe.style.border = 'none';
      container.appendChild(iframe);
      iframe.doc = null;
      if(iframe.contentDocument)
        iframe.doc = iframe.contentDocument;
      else if(iframe.contentWindow)
        iframe.doc = iframe.contentWindow.document;
      else if(iframe.document)
        iframe.doc = iframe.document;
      iframe.doc.open();
      iframe.doc.close();
      iframe.doc.location.href=url;
    ]]>
    </script>
  </body>
</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">
</script>

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!

Follow

Get every new post delivered to your Inbox.