如何在构建成功完成时以编程方式设置 "Retain Indefinitely" 字段?

How to programmatically set the "Retain Indefinitely" field when a build successfully completes?

我正在寻找一种方法来设置构建完成时的无限期保留字段。

也许使用 PowerShell 脚本作为构建步骤?

查看 "Build Updating Tasks" extension。它包含一个构建保留任务。它正是你所需要的。如果我没记错的话,您确实需要使用 TFS 更新 3。

为了使用 vNext 构建的搜索者的利益,您可以使用 Powershell 脚本来执行此操作。

您需要在构建选项中'Allow scripts to access OAuth token'。

$buildId = $env:BUILD_BUILDID # the currently running build
"Build ID: $buildId"

$keepforever = @{
    keepforever='true'
}

$jsonKeepForever = $keepforever | ConvertTo-Json -Depth 100

$uriForBuildUpdate = "$($env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI)$($env:SYSTEM_TEAMPROJECTID)/_apis/build/builds/" + $buildID + "?api-version=2.0"

$result = Invoke-RestMethod -Uri $uriForBuildUpdate -Method Patch -Body $jsonKeepForever -ContentType "application/json" -Headers @{ Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN" }

Write-Verbose "Result: $result" -Verbose

"********************************"
"Build set to retain indefinitely"
"********************************"