TeamCity Service Messages Library for .NET

TeamCity uses Service Messages to provide an easy API to allow for build scripts integration, i.e. the build providing status reports, artifacts publishing, test reporting, etc. A Service Message has the following format:

##teamcity[hello message='teamcity' version='6.5.x' comment='awesome']

Service Messages introduce a communication protocol for data exchanges  between processes using streams, sockets, HTTP or pipes.

I’ve created a wrapper to allow for easier interaction with TeamCity Service Messages, providing it as a package available on NuGet.

Usage

PM> Install-Package TeamCity.ServiceMessages

The library contains two main classes. One for reading and one for writing service messages.

Reading service messages

Reading service messages can be done using a TextReader or string with minimal memory requirements:

Parse method gives us an IEnumerable of IServiceMessage:

The Name is the name of service message, i.e. ‘name’ in ##teamcity[name'aaa'].
The DefaultValue contains simple value, i.e. ‘value’ for ##teamcity[name 'value'] or null for service message with attributes, i.e. ##teamcity[name tea='hot' ice='cold']. To access service message attributes use Keys property and GetValue method.

Writing service messages

To create a service message you may use anonymous type for service message attributes:

The previous is the simplest way for creating service messages, although you may use a strongly typed approach:

Summary

The source code for the project is available on GitHub and the build is at TeamCity.CodeBetter.Com and with TeamCity support for NuGet, it automatically publishes the library as NuGet package on NuGet.org. For a full description of the format and usages of Service Messages see the Build Script Integration with TeamCity article.

This entry was posted in FYI, Tips&Tricks and tagged , . Bookmark the permalink.

2 Responses to TeamCity Service Messages Library for .NET

  1. Simone says:

    Hi Eugene, sorry if I’m missing something, but what would I use this for?

  2. Eugene says:

    Simone,
    Thank you for question. It is a good question and I mostly expect it would be asked.

    What this library to, actually is formatting and reading of service messages. Actually, this involves escaping for some symbols as described at http://bit.ly/sVOxT9. On that documentation page you find listing of service messages that TeamCity supports.

    In future, I plan to add some TeamCity specific classes to provide higher level API for build script integration.

    For example, you may consider using this library to report tests or publishes build artifacts.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">