Tfsbuild delete/destroy
only availabe for Xaml builds. And need to delete
first then destroy
.
For vNext builds, you can try to delete them with the REST API (Delete a build):
DELETE http://server:8080/tfs/DefaultCollection/ProjectName/_apis/build/builds/{build Id}?api-version=2.0
You can use below PowerShell script to delete all the builds which compeleted in the year 2017 for the specific build definiiton:
Param(
[string]$collectionurl = "http://server:8080/tfs/Collection",
[string]$projectName = "ProjectName",
[string]$builddefinitionID = "56",
[string]$keepForever = "true",
[string]$user = "username",
[string]$token = "password"
)
# Base64-encodes the Personal Access Token (PAT) appropriately
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))
#Get builds list which completed in the year 2017
$buildsUrl = "$($collectionurl)/$projectName/_apis/build/builds?definitions=$builddefinitionID&statusFilter=completed&api-version=2.0"
$builds = (Invoke-RestMethod -Uri $buildsUrl -Method Get -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}).value | where({$_.finishTime -like '*2017*'})
#Delete the builds
foreach ($build in $builds.id)
{
$deleteurl = "$($collectionurl)/$projectName/_apis/build/builds/$build"+"?api-version=2.0"
$result = (Invoke-RestMethod -Uri $deleteurl -Method Delete -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)})
Write-Host "Builds deleted with the ID" : $build
}