TFS API Part 34– Build Basic Actions

24/01/2011

TFS API Part 34– Build Basic Actions

In my previous post on on TFS API– Get Build Definitions and Build Details I’ve showed how to obtain Builds Definitions and Builds using TFS API.
In this post I’ used the same project but I’ve added more functionality to the UI that will allow you to perform more actions on the Build item (Stop, Delete etc).

image

Download Demo Project

Step 1: Create Project and Add Reference

Create an WPF/WinForm application and add the following references:

First add reference for

  • Microsoft.TeamFoundation.dll
  • Microsoft.TeamFoundation.Build.Client
  • Microsoft.TeamFoundation.Build.Common.dll
  • Microsoft.TeamFoundation.dll

All files located under – c:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ReferenceAssemblies\v2.0\

Step 2: Connect to Team Foundation Server

(TFS API Part 20: Bye TeamFoundationServer and Welcome TfsTeamProjectCollection)

private TfsTeamProjectCollection server;
private IBuildServer buildServer;
private void btn_connect_Click(object sender, RoutedEventArgs e)
{
    TeamProjectPicker tpp = new TeamProjectPicker(TeamProjectPickerMode.SingleProject, false);
    tpp.ShowDialog();

    if (tpp.SelectedTeamProjectCollection != null)
    {
        server = tpp.SelectedTeamProjectCollection;
        server.EnsureAuthenticated();
        buildServer = (IBuildServer)server.GetService(typeof(IBuildServer));

        //QueryBuildDefinitions(String) Gets the build definitions for the specified team project.
        //QueryBuildDefinitions(IBuildDefinitionSpec) Gets a single build definition query result for a specified build definition specification.
        //QueryBuildDefinitions(IBuildDefinitionSpec[]) Gets the build definition query results for a specified array of build definition specifications.
        //QueryBuildDefinitions(String, QueryOptions) Gets the build definitions for the specified team project. The specified query options determine the amount of data that is retrieved in the query.
        // IBuildDefinition Interface -> http://msdn.microsoft.com/en-us/library/microsoft.teamfoundation.build.client.ibuilddefinition.aspx
        BuildDefinitions.ItemsSource = buildServer.QueryBuildDefinitions(tpp.SelectedProjects[0].Name);
    }
}

Step 3: Build Actions

Here is the list of some basic methods you can use for BuildDetail.

IBuildDetail build = Builds.SelectedItem as IBuildDetail;
//Delete the build and only the specified information.
//None          No delete options selected.
//DropLocation Delete drop location.
//TestResults Delete test results.
//Label          Delete the label.
//Details      Delete details.
//Symbols      Delete symbols.
//All          Delete all.

build.Delete(DeleteOptions.All); 
//Stops the build.
build.Stop();
//Starts polling by using the default interval of five seconds and no synchronization object.
//When events are handled by a visual Windows Forms component, the other overload should be used for this
//method and that component should be passed in as the synchronizingObject so that the event handlers
//are called on the same thread on which the component was created.
build.Connect();
//Stops polling the server.
build.Disconnect();
//Notifies the server that the build is complete and sets the status accordingly.
BuildStatus item = (BuildStatus)combo_status.SelectedItem;
build.FinalizeStatus(item);

//Blocks additional builds until this build is finished.
build.Wait();

//Retrieves the latest build data from the server with all details.
build.RefreshAllDetails();
 
Enjoy
Download Demo Project

Add comment
facebook linkedin twitter email

Leave a Reply