A project I’m involved with is using JetBrains TeamCity as the continuous integration environment.

One of the metrics we wanted to track on this project was the count of warnings produced when compiling. We hoped that, by giving the warning count visibility, we’d be able to gradually reduce the number of warnings over time.

It turned out that adding this into the statistics tab of our TeamCity environment was pretty easy – easier in fact, than counting the warnings.

Step #1: Counting the Warnings

Our build scripts are based on NAnt, but for the actual compilation step we invoke MSBuild on the commandline.

In order to count the number of warnings produced by compilation, we first needed MSBuild to write a log of the build. This required adding a /logger option to the commandline:

<exec program="${msbuild.dir}\MSBuild.exe">
  <arg file="${solution.file}"/>
  <arg value="/t:rebuild"/>
  <arg value="/verbosity:quiet"/>
  <arg value="/logger:FileLogger,Microsoft.Build.Engine;logfile=${log.file}"/>
</exec>

Once the log file exists, we scan through it, counting each warning we find:

<foreach item="Line" 
         in="${log.file}"
         property="line">
  <do>
    <property name="warning.count"
              value="${int::parse(warning.count) + 1}"
              if="${string::contains( line, 'warning')}"/>
  </do>
</foreach>

At this point, we have a property (warning.count) that contains the metric we want. How to integrate this into TeamCity?

Step #2: Display within TeamCity

The fine bods at JetBrains have built a simple extension mechanism into TeamCity – any build process may write messages to the console that will be picked up by TeamCity.

For our warning count metric, we just echo the value in the required format:

<echo message="##teamcity[buildStatisticValue 
      key='warnings' 
      value='${warning.count}']"/>

The last piece of the puzzle is a one time configuration on the TeamCity server, setting up “Warnings” as a statistic to track. This is one of the very few times when you need to dive directly into a configuration file because there’s no UI available.

Within the TeamCity configuration directory, find the main-config.xml file and add the following right at before the end of the <server> element:

<graph>
  <valueType key="warnings" 
             title="Compilation Warnings (fewer is better)" />
</graph>

Save the changes, restart the TeamCity application server (usually Tomcat) and you’re done.

Viewing Statistics

Each time a build runs, the build file will output the number of warnings and these values will be collected into a graph on the statistics tab for reference:

Better yet, each spot is a link, taking you to the specified build – giving invaluable tracking where you can identify which check-in produced a large rise in the number of warnings.

Comments

blog comments powered by Disqus
Next Post
Single Reponsibility Principle  04 Jan 2009
Prior Post
A Nice Round Number  21 Dec 2008
Related Posts
Browsers and WSL  31 Mar 2024
Factory methods and functions  05 Mar 2023
Using Constructors  27 Feb 2023
An Inconvenient API  18 Feb 2023
Method Archetypes  11 Sep 2022
A bash puzzle, solved  02 Jul 2022
A bash puzzle  25 Jun 2022
Improve your troubleshooting by aggregating errors  11 Jun 2022
Improve your troubleshooting by wrapping errors  28 May 2022
Keep your promises  14 May 2022
Archives
December 2008
2008