构建管道不会删除

Kir*_*eed 7 azure-devops

在Azure DevOps门户中,我选择一个管道,然后选择[...]菜单,然后选择删除.

我看到一条消息:

你确定吗?此操作无法撤消.这将永久删除管道'vt3e(1)'.删除包括所有构建和相关工件.

我输入管道名称并单击"确定",但管道不会删除.

我等了几个小时.

[更新]

Chrome中的F12在控制台中显示错误:

ms.vss-build-web.common-library .__ y__CePsj5f5zdcIK.min.js:18错误:版本保留与请求的管道关联的一个或多个构建.管道(s)和构建版本不会被删除

[更新]

我试图按照David D给出的答案,但是当我去删除一个版本时,我收到了一条消息

VS402946:无法删除"Release-8",因为它当前部署在阶段1的阶段.

[更新]

问题记录在Microsoft

Ell*_*ott 56

如果您删除了相关版本,但仍然收到此错误,解决方法是:

  1. 转到有问题的构建管道。
  2. 在“运行”选项卡下,单独打开每个“运行”
  3. 如果运行被保留,您将在顶部看到一个白色框,其中包含诸如“此运行已被 82(管道)永久保留”之类的文字,在右侧,您将看到一个按钮“查看保留版本”。您可以在此处删除一个或多个保留版本。
  4. 您必须完成每次“运行”并重复此过程

如果该白色框/按钮不可见,则不会保留该特定运行。您可以通过单击右上角的三个点并选择“查看保留版本”来确认

  • “Runs”视图当前在每个保留的运行中显示一个小图钉,如果您有很长的列表,可以更轻松地找到保留的运行。 (4认同)

Ari*_*Ari 15

用于删除构建管道(包括所有构建和租赁)的 2022 年 2 月脚本版本:

#Azure DevOps Personal Access Token
# https://learn.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=azure-devops&tabs=Windows

$personalAccessToken = "<Enter your personal access token here>"
$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($personalAccessToken)"))
$header = @{authorization = "Basic $token"}

$organization = "<Enter your Azure DevOps Organization here>"
$project = "<Enter your Project Name here>"

$pipelineName = "<Enter the Build Pipeline Definition Name to be deleted here>"

#Get all build definitions
# API: GET https://dev.azure.com/{organization}/{project}/_apis/build/definitions/{definitionId}?api-version=6.0
$url = "https://dev.azure.com/$organization/$project/_apis/build/definitions?api-version=6.0"
$allBuildDefinitions = Invoke-RestMethod -Uri $url -Method Get -ContentType "application/json" -Headers $header

$allBuildDefinitions.value | Where-Object {$_.name -eq $pipelineName} | ForEach-Object {
    Write-Host $_.id $_.name $_.queueStatus
 
    # For debugging reasons, just to be sure that we don't delete the wrong build pipeline
    if ( $_.name -ne $pipelineName ) {
        return;
    }

    #Get all Builds for a Definition
    # API: GET https://dev.azure.com/{organization}/{project}/_apis/build/builds?definitions={definitions}&queues={queues}&buildNumber={buildNumber}&minTime={minTime}&maxTime={maxTime}&requestedFor={requestedFor}&reasonFilter={reasonFilter}&statusFilter={statusFilter}&resultFilter={resultFilter}&tagFilters={tagFilters}&properties={properties}&$top={$top}&continuationToken={continuationToken}&maxBuildsPerDefinition={maxBuildsPerDefinition}&deletedFilter={deletedFilter}&queryOrder={queryOrder}&branchName={branchName}&buildIds={buildIds}&repositoryId={repositoryId}&repositoryType={repositoryType}&api-version=6.0
    $url = "https://dev.azure.com/$organization/$project/_apis/build/builds?definitions=" + $_.id + "&api-version=6.0"
    $allBuildsOfDefinition = Invoke-RestMethod -Uri $url -Method Get -ContentType "application/json" -Headers $header
 
    #Process each Build of Definition
    $allBuildsOfDefinition.value | Where-Object {$_.retainedByRelease -eq "True"} | Sort-Object id | ForEach-Object {
        #Report on retain status
        Write-Host "Build Id:" $_.id " retainedByRelease:" $_.retainedByRelease

        #Get all Retention Leases for this Build
        # API: GET https://dev.azure.com/{organization}/{project}/_apis/build/builds/{buildId}/leases?api-version=7.1-preview.1
        $url = "https://dev.azure.com/$organization/$project/_apis/build/builds/" + $_.id + "/leases?api-version=7.1-preview.1"
        $allLeasesOfBuild = Invoke-RestMethod -Uri $url -Method Get -ContentType "application/json" -Headers $header

        #Delete each Lease of Build
        $allLeasesOfBuild.value | ForEach-Object {
            #Delete Lease
            # API: DELETE https://dev.azure.com/{organization}/{project}/_apis/build/retention/leases?ids={ids}&api-version=7.1-preview.2
            $url = "https://dev.azure.com/$organization/$project/_apis/build/retention/leases?ids=" + $_.leaseId + "&api-version=7.1-preview.2"
            Invoke-RestMethod -Uri $url -Method Delete -ContentType "application/json" -Headers $header

            #Report on Lease deleted
            Write-Host "Lease Id:" $_.leaseId " deleted"
        }

        #Delete Build
        # API: DELETE https://dev.azure.com/{organization}/{project}/_apis/build/builds/{buildId}?api-version=7.1-preview.7
        $url = "https://dev.azure.com/$organization/$project/_apis/build/builds/" + $_.id + "?api-version=7.1-preview.7"
        Invoke-RestMethod -Uri $url -Method Delete -ContentType "application/json" -Headers $header

        #Report on Build deleted
        Write-Host "Build Id:" $_.id " deleted"
    }

    #Delete the Build Definition
    # API: DELETE https://dev.azure.com/{organization}/{project}/_apis/build/definitions/{definitionId}?api-version=6.0
    $url = "https://dev.azure.com/$organization/$project/_apis/build/definitions/" + $_.id + "?api-version=6.0"
    Invoke-RestMethod -Uri $url -Method Delete -ContentType "application/json" -Headers $header
    
    Write-Host "Build Definition:" $pipelineName " (" $_.id ") deleted"
}
    
Write-Host "Habe fertig!"
Run Code Online (Sandbox Code Playgroud)


Dav*_*d D 12

我遇到了同样的问题并尝试了不同的浏览器,平台等.我发现通过在发布选项卡下手动删除每个版本,返回构建然后尝试删除管道再次为我工作.

  • 我遇到的问题是我什至无法删除该版本,因为它处于失败状态。我回去编辑管道,删除了整个阶段。这样我就可以删除该版本,然后再删除管道。 (2认同)

Mur*_*ali 9

在此处输入图像描述 在此处输入图像描述我遇到了以下相同的问题

与所请求的管道关联的一个或多个构建由版本保留。管道和构建不会被删除。

解决这个问题很简单,只需打开要删除的管道,如果您在管道中看到了这一点,只需单击三个点 [查看保留租约],然后打开查看保留租约,然后单击删除所有选项并关闭弹出窗口。[运行保留]。执行此操作后,您现在可以自由地删除所需的管道。


Reg*_*ggi 7

上周我遇到了同样的问题,我更新了某人的脚本以使用 5.1 API。此脚本将在发布管道保留的所有构建上运行。您将需要对您不希望所有构建都从发布中删除的进行一些调整。

$tfsServerURL = "https://dev.azure.com/{organisation}"
$TFSProject = "{project}"

$AzureDevOpsPAT = "{token}"
$AzureDevOpsAuthenicationHeader = @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($AzureDevOpsPAT)"))}
 
#Set to $true to update builds by settingretainingByRelease= false
$CorrectError = $true
 
$URL = "$($tfsServerURL)/$($TFSProject)"
Write-Output $URL
#Get all builddefinitions in Project
$Buildefinitions = (Invoke-RestMethod -Uri ($URL + '/_apis/build/definitions?api-version=5.1') -Method GET -UseDefaultCredentials -Headers $AzureDevOpsAuthenicationHeader).value
 
foreach($Builddefiniton in $Buildefinitions)
{
    Write-Output "Searching in $($Builddefiniton.name) with id $($Builddefiniton.id)"
    #Get Builds with keepforever = false and retainedByRelease = true
    
    $Builds = (Invoke-RestMethod -Uri ($URL + '/_apis/build/builds?definitions=' + $Builddefiniton.id + '&api-version=5.1') -Method GET -UseDefaultCredentials -Headers $AzureDevOpsAuthenicationHeader).value | where {$_.keepForever -eq $False -and $_.retainedByRelease -eq $true}
     
    #Get releases linked to the build

    foreach ($build in $Builds)
    {
        If ($CorrectError)
        {
            Invoke-RestMethod -Uri ($URL + '/_apis/build/builds/'+ $build.id + '?api-version=5.1') -Method Patch -Body (ConvertTo-Json @{"retainedByRelease"='false'}) -UseDefaultCredentials -Headers $AzureDevOpsAuthenicationHeader -ContentType "application/json" | Out-Null
            Write-Output "`tFixed"
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

PowerShell 脚本将首先获取所有构建管道,然后获取所有未无限保留并由发布保留的构建。如果将 CorrectError 设置为 true,则脚本将尝试将 reservedByRelease 标志切换为 false。

运行此脚本后,我能够删除构建管道。

  • 好建议,上面的异常行 14 和 21(第一个剩余的 get 调用)需要使用 PAT,否则将无法针对 Azure DevOps 进行身份验证。在 -UseDefaultCredentials 之后附加: -Headers $AzureDevOpsAuthenicationHeader (3认同)

Mat*_*ker 5

如果我尝试删除管道,我会得到同样的错误:

与所请求的管道关联的一个或多个构建由版本保留。管道和构建不会被删除。

在管道页面上,转到“运行”选项卡,应该会看到记录列表。如果单击该行右侧的三个点,您应该会看到一个查看保留租约的选项。如果您删除全部,您应该能够删除该行。然后,您需要对运行选项卡中的每一行重复此步骤,直到删除所有运行。

只有这样您才能删除父管道。