Martin Woodward posted a few weeks ago about his build bunny. Now this is something I had tried a while ago for DDD4, but hit the same problem Martin had that the old Nabaztag API was too slow and messages could take hours to arrive, making it useless in the real world. Inspired by Martin and the new faster API I have been working on a new Team Build status monitor for the office.
Getting most of it going is straight forward as Martin said, the TFS API event model is easy to use. However I did have a problem getting the details of the build. I could see if it built or not, but I could not get any count of warning, code analysis errors or test results etc.
It seems the problem is that when the BuildQueue_StatusChanged event fires after a build completes it does not have all the details in the IBuildDetail object you would expect. However, if you re-query the TFS server you can get the information.
I added the following to the end of the BuildQueue_StatusChanged event handler:
// first get the handle to the queue (you might have this stored already)
TeamFoundationServer tfs = new TeamFoundationServer(“http://myserver:8080”);
IBuildServer buildServer = (IBuildServer)tfs.GetService(typeof(IBuildServer));
IQueuedBuildsView buildQueue = buildServer.CreateQueuedBuildsView(“MyProject”);
// Now re query using the project build URL to get the number of errors and warning
// the array of string list what details we want
IBuildDetail buildDetails = buildServer.GetBuild(buildQueue.QueuedBuilds
[lastItem].Build.Uri, new string[] {
TeamFoundation.Build.Common.InformationTypes.ConfigurationSummary,
TeamFoundation.Build.Common.InformationTypes.TestSummary,
TeamFoundation.Build.Common.InformationTypes.CodeCoverageSummary,
TeamFoundation.Build.Common.InformationTypes.CompilationSummary},
QueryOptions.None);
// Now use the new IBuildDetail object to update the screen associated display
// user control
this.display.UpdateStatus(buildDetails);Now in my display usercontrol all I need to go is to extract compiler summary details using a standard TFS InformationNodeConverter (and you could do the same for test or code coverage).
var buildSummaries = InformationNodeConverters.GetConfigurationSummaries(build Details);
if (buildSummaries.Count > 0)
{
this.lblCompileReport.Text = “[Errors:” + buildSummaries[0].TotalCompilationErrors +
“] [Warnings:” + buildSummaries[0].TotalCompilationWarnings +
“] [Static Analysis Errors:” + buildSummaries[0].TotalStaticAnalysisErrors +
“] [Static Analysis Warnings:” + buildSummaries[0].TotalStaticAnalysisWarnings +"]";
}