gpt4 book ai didi

azure-devops - 如何使用 Legacy 保留模型删除运行

转载 作者:行者123 更新时间:2023-12-05 05:58:18 31 4
gpt4 key购买 nike

由于 Legacy retention model 的原因,我有一些运行被保留,如下所示:

enter image description here

我不确定它来自哪里。我想删除它们,但不想通过每次运行和删除租约。有办法吗?

最佳答案

我没有在 Azure DevOps 上找到关闭它的设置,所以我编写了 powershell 脚本,它遍历每个管道定义,然后构建和删除 Legacy Retention Mode 租约并使用此租约构建。

$AzureDevOpsAuthenicationHeader = @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":your-pat-here")) }

$organization = "org-name"
$project = "project-name"

$definitionsUrl = "https://dev.azure.com/${organization}/${project}/_apis/build/definitions?api-version=6.0"

$definitions = Invoke-RestMethod -Uri $definitionsUrl -Method Get -Headers $AzureDevOpsAuthenicationHeader

foreach ($definition in $definitions.value)
{
Write-Host $definition.name -ForegroundColor Green

$pipelineUrl = "https://dev.azure.com/${organization}/${project}/_apis/pipelines/$($definition.id)/runs?api-version=6.0-preview.1"

# Invoke the REST call
$result = Invoke-RestMethod -Uri $pipelineUrl -Method Get -Headers $AzureDevOpsAuthenicationHeader

foreach ($run in $result.value) {
$leasesUrl = "https://dev.azure.com/${organization}/${project}/_apis/build/builds/$($run.id)/leases?api-version=6.1-preview.1"

$leasesResult = Invoke-RestMethod -Uri $leasesUrl -Method Get -Headers $AzureDevOpsAuthenicationHeader

$ownerId = "Legacy Retention Model"
foreach ($lease in $leasesResult.value) {
if($lease.ownerId -Match $ownerId){

$deleteLeaseUrl = "https://dev.azure.com/${organization}/${project}/_apis/build/retention/leases?ids=$($lease.leaseId)&api-version=6.0-preview.1"

Write-Host "Removing ${ownerId} from run $($run.id) (created date $($run.createdDate))" -ForegroundColor Blue

$leasesResult = Invoke-RestMethod -Uri $deleteLeaseUrl -Method Delete -Headers $AzureDevOpsAuthenicationHeader
Write-Host "Removed lease"

$deleteBuildUrl = "https://dev.azure.com/${organization}/${project}/_apis/build/builds/$($run.id)?api-version=6.0"

$leasesResult = Invoke-RestMethod -Uri $deleteBuildUrl -Method Delete -Headers $AzureDevOpsAuthenicationHeader
Write-Host "Removed build"
}
}
}
}

关于azure-devops - 如何使用 Legacy 保留模型删除运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68556752/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com