Retain builds from Release Management

When releasing with Microsoft Release Manager “vNext” the linked builds don’t automatically get marked as retained forever. If you want to be able to re-deploy released builds you want to ensure the builds are not deleted by retention polices. It’s a good idea to let the release definition take care of this (at some point, perhaps in the release to production stage) and mark the released builds as retained.

Here’s a PowerShell script that gets the builds used in the release and set the “keep forever” flag on the builds:

image

You can use this from your release definition either by including the script in one of the build artifacts and reference it or using an in-line PowerShell script step:

image

Note: the script above works with an on-prem TFS (using default credentials), if you want to use it with VSTS you need to include an authentication header instead and pass a personal access token.

$username = “”
$password = “PASTE-YOUR-PERSONALACCESSTOKEN-HERE”
$basicAuth = (“{0}:{1}” -f $username,$password)
$basicAuth = [System.Text.Encoding]::UTF8.GetBytes($basicAuth)
$basicAuth = [System.Convert]::ToBase64String($basicAuth)
$headers = @{Authorization=(“Basic {0}” -f $basicAuth)}

Then replace the –UseDefaultCredentials with -headers $headers.

Get the complete script here (rename to .ps1).

Leave a Reply

Your email address will not be published. Required fields are marked *