如何删除声称由版本保留的 Azure DevOps 构建定义? [英] How can I delete an Azure DevOps build definition that it claims is retained by a release?

查看:11
本文介绍了如何删除声称由版本保留的 Azure DevOps 构建定义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试删除 Azure DevOps 构建定义,但它不会让我删除,因为它说:

与请求的管道关联的一个或多个构建由发布保留.管道和构建将不会被删除."

但是,没有明显的方法可以查看导致保留构建的版本.当然,我尝试在线搜索,但是所有关于如何在 Web UI 中执行此操作的示例/屏幕截​​图都显示了 Azure DevOps 网站多次迭代之前的 UI,因此所有控件看起来都不再相同.例如,我在任何地方都没有看到锁定图标.

如何找到保留这些构建定义的版本,以便我可以删除它们,然后删除构建定义?

谢谢!

解决方案

打开构建管道查看其详细的构建记录时,可以看到相关的发布名称及其链接:

在旧的管道版本上,有一个锁定图标,可以明显地让我们知道它被保留了.事实上,锁图标不仅意味着它被释放保留,手动构建保留也会显示这个图标.但是,在我们扩展新的 sprint 时,我们似乎错过了这个明显的图标.

作为获取发布保留的构建列表的解决方法,这里有一个简短的脚本可以帮助您使用 Rest api 实现:

$token = "{PAT 令牌}"$url ="https://dev.azure.com/{org name}/{project name}/_apis/build/builds?api-version=5.1"$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($token)"))$response = Invoke-RestMethod -Uri $url -Headers @{Authorization = "Basic $token"} -Method Get$results = $response.value |其中 {$_.retainedByRelease -eq "true"} #|写主机结果 = $($results.id | ConvertTo-Json -Depth 100)"

首先,使用 list builds api 获取当前项目中的所有构建.然后对于发布保留的构建,因为有一个参数可以表明它:

上面的脚本非常通用,可以在Powershell-ise和Powershell命令行以及VSTS的Powershell任务中使用,无需任何更改.

2019 年 11 月更新:

根据@Auth 的评论,如果想要获取其关联的发布,最简单的方法是找到构建,然后检查其关联的发布管道,如我上面分享的截图所示.

如果这不能满足您的要求,并且我们使用的以前的 API 中没有包含任何发布信息,那么在这里,您需要使用此 API:

<小时>

缺少图标,会通知相应的团队,并在以后的 sprint 中尝试添加.

I'm trying to delete an Azure DevOps build definition but it won't let me since it says:

"One or more builds associated with the requested pipeline(s) are retained by a release. The pipeline(s) and builds will not be deleted."

However there's no obvious way to see what release is causing a build to be retained. I tried searching online, of course, but all the examples/screenshots of how to do this in the web UI are showing UI from several iterations ago of the Azure DevOps website so none of the controls look the same anymore. I don't see a lock icon anywhere, for example.

How can I find the releases that are holding onto these build definitions so I can delete them and then delete the build definition?

Thanks!

解决方案

When you open the build pipeline to see its detailed build records, you can see the relevant release name and its link:

On old pipeline version, there had a lock icon which can obvious let us know it is retained. In fact, the lock icon not only means it is retained by release, manual build retain also show this icon. But, seems we missed this obvious icon while we expand the new sprint.

As a workaround to get list of builds which retained by release, here has a short script can help you achieve by using Rest api:

$token = "{PAT token}"

$url ="https://dev.azure.com/{org name}/{project name}/_apis/build/builds?api-version=5.1"

$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($token)"))

$response = Invoke-RestMethod -Uri $url -Headers @{Authorization = "Basic $token"} -Method Get

$results = $response.value | Where {$_.retainedByRelease -eq "true"} #|

Write-Host "results = $($results.id | ConvertTo-Json -Depth 100)"

First, use list builds api to get all builds that in current project. Then for the builds which retained by release, since there has a parameter can indicate it: retainedByRelease here I use $_.retainedByRelease -eq "true" to get the builds list which actual retained by release:

The above script is very universal, can be used in Powershell-ise and Powershell Command Line and the Powershell task of VSTS without change anything.

Update in 11/19:

Based on @Auth's comment, if want to get its associated release, the most easiest way is find the build, and then check its associate release pipeline as the screenshot shown I shared above.

If this does not satisfied what you want, and the previous API we used does not include any releases info in that, so here, you need use this API: Releases - Get Release:

GET https://vsrm.dev.azure.com/{org name}/{project name}/_apis/release/releases?sourceId={project id}:{build definition id}&api-version=5.1

In this API, you need specified the project id:build definition id to filter releases.


With the icon missing, will let the corresponding team know and try to add it in the future sprint.

这篇关于如何删除声称由版本保留的 Azure DevOps 构建定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆