Retrieving the current iteration from a TFS Build vNext

One of my clients wanted to include the current iteration name in the build number format.
I created a PowerShell script to retrieve it into a build variable named Build.PackageVersion

$Uri = "$(System.TeamFoundationCollectionUri)/$(System.TeamProject)/$(System.Team)/_apis/work/TeamSettings/Iterations?`$timeframe=current&api-version=3.0"
$Response = Invoke-RestMethod -Method Get -UseDefaultCredentials -ContentType application/json -Uri $Uri
$IterationName = $Response.value.name

Write-Host "##vso[task.setvariable variable=Build.PackageVersion;]$IterationName"

The System.Team variable is a custom one to avoid hard coding inside the script. 
The script is executed via a build task from the marketplace: https://marketplace.visualstudio.com/items?itemName=ms-devlabs.utilitytasks

Then I used the tasks from Jesse Houwing to update the build number at build time: https://marketplace.visualstudio.com/items?itemName=jessehouwing.jessehouwing-vsts-variable-tasks

Comments

Popular posts from this blog

Create a draft release and start it using the TFS REST API

Adding a delay before processing Textbox events

Change the deployment URL of a ClickOnce application