Scott Stafford
Scott Stafford

Reputation: 44818

How do you delete a TFS build using the Build API?

The TFS Build API is pathetically underdocumented on MSDN. How do I delete an existing build definition through the API?

(I want to delete one before I make a replacement with updated settings...)

Upvotes: 1

Views: 1069

Answers (2)

bhard
bhard

Reputation: 94

Here you can specify a particular build (drop folder only)

var bs = tpc.GetService<IBuildServer>();
var bSpec = bs.CreateBuildDetailSpec(projectName, buildDefinitionName);
bSpec.QueryOptions = QueryOptions.None;
bSpec.InformationTypes = null;
bSpec.QueryDeletedOption = QueryDeletedOption.ExcludeDeleted;

var targetBuild = bs.QueryBuilds(bSpec).Builds.Where(b => b.Uri == build.Uri).ToArray();
bs.DeleteBuilds(targetBuild, DeleteOptions.DropLocation);

Upvotes: 1

Scott Stafford
Scott Stafford

Reputation: 44818

This seems to be working for me (found via trial and error) so far.

try
{
    var def = buildServer.GetBuildDefinition(
        teamProject, buildDefinition.Name, QueryOptions.Definitions);
    buildServer.DeleteBuilds(def.QueryBuilds());
    def.Delete();
}
catch (Microsoft.TeamFoundation.Build.Client.BuildDefinitionNotFoundException)
{
    // didn't exist, so do nothing..
}

Upvotes: 2

Related Questions