Configuring Hudson/Jenkins to parse MSBuild output
When I started with continuous integration, I used CruiseControl.NET, but the XML configuration quickly got to be really tedious.
It didn’t take me long to switch to Hudson CI. It’s free, and it’s easily managed through an intuitive web interface. Not that I can’t grok XML configuration files; I’d just rather be spending my time building things instead of figuring out how to get them built.
For a primer on how to use Hudson CI for .NET projects, take a look at Getting Started With CI Using Hudson For Your .NET Projects by Bob Cravens, or Continuous Integration with Hudson and .NET (dead link - snapshot from the Wayback Machine).
The only problem is Hudson is Java-based, so it’s not exactly plug-n-play when it comes to .NET, MSBuild, and Visual Studio. Particularly, when a build failed, I would have to scan through hundreds of lines looking for the cause of the error, which is difficult to do with CTRL-F when this line is completely normal:
Compile complete -- 0 errors, 0 warnings
What is needed is the Log Parser Plugin (link includes formatting rules), which allows you to define regular expressions that determine how to interpret the lines of content in the MSBuild output, so that warnings and errors can be called out in different colors the same way that Visual Studio does. This plugin can be installed through Hudson’s built-in plugin manager, but you have to configure it yourself.
First, you need to create a text file on the server that hosts Hudson. If you have a cluster of servers, this must be done on the master server.
Then, define the rules for the Log Parser Plugin to use. For this, it is helpful to have a reference of
Here are the rules that I came up with, which I saved to C:\hudson\VSParsingRules.txt:
# Divide into sections based on project compile start start /^------/ # Compiler Error error /(?i)error [A-Z]+[0-9]+:/ # Compiler Warning warning /(?i)warning [A-Z]+[0-9]+:/
It’s really not complex. A line starting with 5 dashes defines the start of a section where MSBuild starts building a project. Then there are rules to define an error and a warning.
Once this file is in place, go to Manage Hudson > Configure System and enter the path to the rules file under Console Output Parsing. Then, in the configuration for each project, under “Post-build Actions”, check “Console output (build log) parsing” and select the appropriate rules from the drop-down.
Once the next build is finished, you will see a new “Parsed Console Output” link in the left-menu on each build.
One last tip: you will want to disable the Automatic Refresh setting (in the top-right corner of your browser window) while viewing parsed log output so that your screen doesn’t flicker and refresh every few seconds, causing you to lose your place.