tfsbuild delete/destroy - founds no builds for build specification

只谈情不闲聊 提交于 2019-12-07 08:18:26

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 
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!