Geeks in the West Country

TeamCity MSBuild tasks

January 24, 2008 · 8 Comments

For our latest product, we’ve switched over from CC.NET to the excellent TeamCity continuous integration server from JetBrains, which, as of version 3, is free for small projects like ours. One of the nice aspects of TC is that it’s very easy to publish data from your build (such as number of unit test passes / failures) so that it gets picked up by the TC server.

To help us along, we’ve written a few simple MSBuild tasks which do just that. We’ve created a sourceforge project for them, but until that’s activated, you can download them here.

There are currently 3 tasks:

MSBuild.TeamCity.Tasks.TeamCityAppendStatusText

Appends text to be displayed in the build status when the build is complete – e.g. “Tests Passed: 3, Tests Failed: 1″

Example usage:

<TeamCityAppendStatusText TeamCityInfoPath="$(teamcity_build_checkoutDir)\teamcity-info.xml" Value="Tests Passed: 3" />
<TeamCityAppendStatusText
TeamCityInfoPath="$(teamcity_build_checkoutDir)\teamcity-info.xml" Value="Tests Failed: 1" />

MSBuild.TeamCity.Tasks.TeamCityAddStatistic

Adds a build statistic that can be picked up for graphing by configuring TeamCity’s main-config.xml (see here).

Example usage:

<TeamCityAddStatistic TeamCityInfoPath="$(teamcity_build_checkoutDir)\teamcity-info.xml" Key="TestsPassed" Value="3" />
<TeamCityAddStatistic
TeamCityInfoPath="$(teamcity_build_checkoutDir)\teamcity-info.xml" Key="TestsFailed" Value="1" />

MSBuild.TeamCity.Tasks.TeamCityAddStatisticList

Variation on the above which allows you to add multiple statistics at once. Each key/ value pair is delimited by ‘;’

Example usage:

<TeamCityAddStatisticList TeamCityInfoPath="$(teamcity_build_checkoutDir)\teamcity-info.xml" KeyValuePairs="TestsPassed=3;TestsFailed=1" />

Thats pretty much it for now as  that’s all we’re using. I’ll post a follow up shortly to show how you can use these to pull in results from MbUnit tests.

If you missed the link above, you can download the tasks here.

Categories: Microsoft
Tagged: , ,

8 responses so far ↓

  • Elizaveta // January 25, 2008 at 9:30 am | Reply

    Thank you so much for your positive feedback.

    We are really glad you managed to implement custom builds’ data publishing and share your knowledge with others.

    The JetBrains TeamCity Team

  • Petar Petrov // January 29, 2008 at 4:04 pm | Reply

    Great article. Please provide a serie with more details on MSBuild, TeamCity and how to setup a new project.

  • Brett Veenstra // March 7, 2008 at 2:25 pm | Reply

    Great stuff here… I’m definitely interested in how you hooked this into your MSBuild script (although we’re going to use NANT for now).

  • Eugene Petrenko // June 25, 2008 at 10:05 am | Reply

    Unfortunatly the link to the soureces is dead not. Is there any other way for achieving it. I believe it would be possible to posting those code in TeamCity plugins repository.

  • Will // July 1, 2008 at 11:34 am | Reply

    Thanks Eugene – have fixed that link now.

  • Korayem // September 8, 2008 at 8:40 am | Reply

    Thanks for sharing this information. Please excuse my ignorance but I read this blog post and your forum post and still can’t figure out what to do exactly.

    I understand that i have to configure the artifact to fetch the generated mbunit dll files, but then what?

  • Will // September 8, 2008 at 9:09 am | Reply

    Hi Korayem. Yes, the post assumes you already have TeamCity running your MbUnit tests and generating an HTML report. MBUnit ships with an MSBuild task which you can call to run your tests (http://docs.mbunit.com/help/html/MbUnitInAnAgileEnvironment/MbUnitAndMSBuild.htm). This generates an HTML report which you can include in you artifacts path so you get a test report with every build :-)

    Once you have that, you can use these MSBuild tasks to report information back to the TeamCity dashboard so you don’t have to dig into the artifacts to find out if the tests failed.

    In our project, we have a “TeamCityBuild” MSBuild target which builds the project, runs the tests and writes to the teamcity-info file.

    Hope this helps – please let me know if you’re still struggling.

  • Alexander Groß // September 16, 2008 at 11:37 pm | Reply

    Hi Will,

    I’ve ported your tasks over to NAnt (my preferred build tool) and added a couple of other (NAnt) tasks specific to TeamCity. Would you mind re-publishing them under a BSD license given that I credit your excellent work? Which form of commendation do you prefer?

    Thanks,

    Alex

Leave a Comment