I thought this was a very cleaver idea and set out to help. I already blogged how to set the Retain Indefinitely flag
here. So all we need is a PowerShell script to allow us to set the build quality. If you are using the agent based deployment you can add the AgentBasedSetBuildQualityPowerShell script as a custom tool. If you are using the vNext based deployment you can simply execute the vNextSetBuildQuality PowerShell using the PS/DSC action. When using a vNext based deployment the $tfsUrl, $teamProject and $buildDefinition values are automatically passed to all PowerShell scripts. When using the agent based solution you will need to add those as parameters when you add the PowerShell as a custom tool. You can then use the Helper Variables provided by Release Management to pass in the correct values. You can see an example of adding an agent based custom tool
here.
function set-BuildQuality
{
[CmdletBinding()]
param(
[string] $buildQuality
)
# The machine
you use to execute this PowerShell must have Team Explorer installed
# so that we
can load the needed assemblies.
# The [void]
stops the GAC messages from being output to screen.
Write-Verbose
"Loading assemblies"
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Client")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Build.Client")
# Connect to
TFS
Write-Verbose
"Connecting to $tfsUrl"
$teamProjectCollection
= [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($tfsUrl)
# Get the
build service
$buildServer
= $teamProjectCollection.GetService([type]"Microsoft.TeamFoundation.Build.Client.IBuildServer")
# Find the
build used for this release
$buildSpec
= $buildServer.CreateBuildDetailSpec($teamProject, $buildDefinition)
# Don't query
any additional information i.e. associated work items, associated changesets,
etc.
$buildSpec.InformationTypes
= $null
# Use the
build number to find the build
$buildSpec.BuildNumber =
$buildNumber
# Search for
the build
$results
= $buildServer.QueryBuilds($buildSpec)
# Make sure
we only found a single build
if($results.Builds.Count -eq 1)
{
Write-Verbose
"Build Found"
$build
= $results.Builds[0]
$build.Quality = $buildQuality
$build.Save()
Write-Verbose
"Build Quality set to $buildQuality"
}
}