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).
Step 1: Create Project and Add Reference
Create an WPF/WinForm application and add the following references:
First add reference for
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
private TfsTeamProjectCollection server;
private IBuildServer buildServer;
private void btn_connect_Click(object sender, RoutedEventArgs e)
TeamProjectPicker tpp = new TeamProjectPicker(TeamProjectPickerMode.SingleProject, false);
if (tpp.SelectedTeamProjectCollection != null)
server = tpp.SelectedTeamProjectCollection;
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.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.
//Stops the build.
//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.
//Stops polling the server.
//Notifies the server that the build is complete and sets the status accordingly.
BuildStatus item = (BuildStatus)combo_status.SelectedItem;
//Blocks additional builds until this build is finished.
//Retrieves the latest build data from the server with all details.