I'm looking for a way to set the retain indefinitely field of a build when it completes.
Maybe using a PowerShell script as a build step?
I'm looking for a way to set the retain indefinitely field of a build when it completes.
Maybe using a PowerShell script as a build step?
For the benefit of searchers using vNext builds, you can use a Powershell script to do this.
You will need to 'Allow scripts to access OAuth token' in the buid options.
$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"
"********************************"
Check out the "Build Updating Tasks" extension. It contains a Build Retention task. It does exactly what you need. You do need to be on Update 3 of TFS if I'm not mistaking.