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 = $

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:

Then I used the tasks from Jesse Houwing to update the build number at build time:

Popular posts from this blog

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

Adding a delay before processing Textbox events

Handling exceptions the right way in WCF (part 2)