0

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?

jessehouwing
  • 106,458
  • 22
  • 256
  • 341
JL.
  • 78,954
  • 126
  • 311
  • 459
  • Are you using Release Management? It seems according to this post that it is set automatically for all builds: http://stackoverflow.com/questions/26259004/release-management-sets-builds-to-retain-indefinitely There is even a answere with how to mod the buildscript to remove "Retain Indefinitely". Maybe you could utilize that mod to undo it, to enable it? – Hyperdingo Jul 18 '16 at 12:53
  • Adding Vs-Team-Services tag as it uses the same build infrastructure. – jessehouwing Jul 18 '16 at 13:47

2 Answers2

2

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"
"********************************"
JsAndDotNet
  • 16,260
  • 18
  • 100
  • 123
1

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.

jessehouwing
  • 106,458
  • 22
  • 256
  • 341
  • Semi works, but I had a 401 unauthorized exception, but I've commented on this, and given the author feedback. – JL. Jul 26 '16 at 09:07