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:
Once the log file exists, we scan through it, counting each warning we find:
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:
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:
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