Behind Brian the Build Bunny

| 5 Comments

Watch the Brian the Build Bunny video in full Since posting about Brian the Build Bunny, I have been getting a steady stream of emails from people who would like to know more about how it works.

Team Foundation Server provides a mechanism by which you can subscribe to events when certain things happen.  This is actually how many of the components in TFS are integrated between themselves and like the rest of the TFS glue - Microsoft make these events available so you can customize your TFS instance.

At a high level, I purchased a Nabaztag bunny and decorated it with the Visual Studio logo and Brian the Build Bunny was born. The code behind Brian the Build Bunny is actually very simple, a web service (in my case sat in IIS on my TFS server) listens for the events and then converts this into a string on text which it sends to the Nabaztag servers.  Nabaztag run this text through a Text to Speech engine and generate an MP3 file with the results, they then notify my build bunny about the MP3 file and he downloads the file over his WiFi connection and plays it on his speakers.

But if you want the full gory details then read on.

Brian the Build Bunny Project.

Pre-requisites:

  • 1 Team Foundation Server instance (a VPC one to play with first is recommended)
  • 1 Nabaztag bunny
  • 1 Wifi connection to the internet for the bunny to use
  • 1 sheet of clear labels (to print the Visual Studio logo as Brian's bow tie).  I used Avery J8560, but then again I'm a crazy European with metric pages.

Preparation:

  1. Ensure your bunny is registered with Nabaztag and you have your serial number and API token.
  2. Ensure your Team Foundation Server instance (or where-ever you want to host the "bunny listener") code has internet access so that it is able to talk to the Nabaztag server.  Try pasting the following URL into Internet Explorer on the TFS instance to make sure you can get out and talk to Nabaztag:
    http://api.nabaztag.com/vl/FR/api.jsp?sn=SERIAL&token=TOKEN&voice=UK-Mistermuggles&tts=Hello+my+name+is+Brian+the+Build+Bunny.

    Remembering to insert your build bunny's serial number and API token obtained when you registered your bunny with Nabaztag.
  3. Download the image teamsystem.png (70 KB) and print out the Team System logo on a clear label.  Cut around the logo and stick onto your bunny to turn him into a smart looking Build Bunny.

Code:

You can download the example code using the following link, (VS 2008 project using C# in .NET 2.0):

sln_download

There are many ways to listen for Team Foundation Server SOAP events. You can have a "proper" web service living on IIS, or you have have a hosted WCF process listening to a particular port. In my particular case I was happy with the IIS approach and so used the excellent Team Foundation Server Notification Event project template from Howard van Rooijen at Conchango as that's the fastest way to get up and running when doing this type of project.  If you wanted to go down the WCF route then take a look at Martin Hinshelwood's TFS Event Handler project up on CodePlex.

I created a quick class library that is a thin wrapper over the Nabaztag API, and exposes functionality via the Bunny class including building and sending of the HTTP message to the Nabaztag servers.
Bunny class diagram 

I then created a TFS Web Services Notification project (using Howard's template).  This gives me ready-made code to hook into various events - but I just wanted the build completion event and the check-in event for this example.

Build completion event:
Build Completition Code

Check-in event:
Code executed on check-in event

As you can see, I really don't do that much - just build up a string based on the data in the TFS event and then send that string to the bunny.

Subscribing the Bunny Listener to the TFS Events

Finally, once the web services are ready and listening - I must now tell TFS to send a SOAP message to my web services at the appropriate time.  To do this, I used the command line tool BisSubscribe.exe.  This can be found on your TFS server in the %ProgramFiles%\Microsoft Visual Studio 2008 Team Foundation Server\TF Setup directory.

If you open up a command prompt and cd to it then you can type:

bissubscribe /eventType BuildCompletionEvent /address http://localhost:8181/bunnylisener/BuildCompletionEndpoint.asmx /deliveryType Soap /server http://localhost:8080
bissubscribe /eventType CheckinEvent /address http://localhost:8181/bunnylisener/CheckInEndpoint.asmx /deliveryType Soap /server http://localhost:8080

Where the webservices are running at http://localhost:8181/bunnylistener.

Exercises for the Reader:

As you can see, the code above is just a starter.  There are many things that you can get this new notification device to do and the code above is designed more of a sample that I can use in a talk rather than full on production code. That said, if anyone is interested in starting up a CodePlex project around this then please drop me a line.  However, the following things are on my TODO list:

  • Subscribe to BuildCompletionEvent2 which has some more relevant information
  • Use the GlobalSecurityService API to obtain the users real names and speak those rather than the userid.
  • Store the bunny config data in web.config rather than hard-coding bunny details in BunnyConstants class
  • Allow multiple bunnies to be registered (perhaps with a UI), allow each voice to be separately configured
  • Make sending of messages to Nabaztag asynchronous

Additionally - rather than using the eventing service to trigger Brian on build completition events, it might be interesting to write the "Bunny Link" as a windows service and get it to subscribe to the build queue using the same API as demonstrated by my Build Wallboard sample.  That way you could make Brian talk when a build was queued or many other things.

If anyone has any questions or would like more details then please drop me a line.

5 Comments

Nice hehehe, we musty do something with builds and Multidomo ;)

This is great Martin! If my manager's manager's manager, can approve the spending request, we might give this a shot! If we do, I'll let you know how it goes.

Cool, though you can't trust the bunny. My own rabbit is not reliable at all and hangs at least twice a day. But its good fun anyway, even when I have to reset it every few hours or so.

Hehe, actually the orginal motivation for my "Team Foundation Server Notification Event project template" project was to get my nabaztag working via TFS! Awesome project.

We are using Team Build for only a couple of days now. After having read about Brian, I got myself a Nabaztag, too. And now guess what... company policies prevent me from getting it connected to the internet... *sigh*

Archives

Creative Commons License
This blog is licensed under a Creative Commons License.