Sdílet prostřednictvím


Team Build API: GetBuildUri and GetBuildDetails

As Buck Hodges recently noted, some Team Build API documentation recently made it up onto MSDN.  Unfortunately, most (maybe all?  I haven't been through it all) of the topics are skeletons, with no real content.  I'll be trying to remedy this by posting fleshed out documentation, sometimes even with examples... 

Thus begins my 35 part series - better know a Proxy. 

First up - the GetBuildDetails method (of the BuildStore class in the Microsoft.TeamFoundation.Build.Proxy namespace).

 public BuildData GetBuildDetails (
    string buildUri
)

This method can be used to obtain information about in-progress or completed builds, including their status, quality, and finish time.  It takes a single parameter, buildUri, which is a string containing the full URI of a build - typically something like:  "vstfs://Build/Build/09012006_010101_000001".  It returns a BuildData object, which contains various details about the build.

Of course, users do not typically know the Uri associated with an individual build, since it is not displayed in any of the standard Team Build GUI.  To come up with a meaningful example, therefore, we'll also have to cover the GetBuildUri method.

 public string GetBuildUri (
  string teamProject,
 string buildNumber
)

This method can be used to obtain a build's Uri given a Team Project and the build's Number.  These can readily be retrieved from the Team Build GUI, though the build number is typically displayed as the build name

Here is an example console application that takes in a Team Foundation Server URL, a Team Project, and a Build Number and displays the corresponding build's Uri, Status, Quality, and Finish Time. 

 using System;
using System.Web.Services;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.Build.Proxy;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string tfsUrl = args[0];
            string teamProject = args[1];
            string buildNumber = args[2];

            TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer(tfsUrl);

            BuildStore buildStore = (BuildStore)tfs.GetService(typeof(BuildStore));

            string buildUri = buildStore.GetBuildUri(teamProject, buildNumber);

            BuildData buildData = buildStore.GetBuildDetails(buildUri);

            Console.WriteLine();
            Console.WriteLine("BuildUri     = " + buildData.BuildUri);
            Console.WriteLine("BuildStatus  = " + buildData.BuildStatus);
            Console.WriteLine("BuildQuality = " + buildData.BuildQuality);
            Console.WriteLine("FinishTime   = " + buildData.FinishTime);
        }
    }
}

Of course, any real application along these lines would do some error checking, display a useful message when invalid arguments were supplied, etc.

Comments

  • Anonymous
    September 14, 2006
    Aaron Hallberg on Team Build API: GetBuildURI and GetBuildDetails.

    Brian Harry on The Next TFS Power...
  • Anonymous
    September 14, 2006
    Aaron Hallberg plans to periodically post descriptions and examples of some of the more relevant Team...
  • Anonymous
    September 15, 2006
    The truthiness of your weblog is always impressive!
  • Anonymous
    September 18, 2006
    Excellent - thanks for noticing the Colbert Report reference...
  • Anonymous
    November 20, 2011
    Is it possible to assign a build number to  a test plan though TFS API?