2
votes

We have a CI build server doing automated builds and would like to include the current sprint/iteration number in the assembly version. Is there an environment variable or easy way of getting the current sprint number in the build processes? TFS On Permise 2015 Update 3

1

1 Answers

8
votes

There isn’t build-in variable to get current sprint, but you can use REST API. Steps:

  1. Add a PowerShell file to the source control (e.g. included in your project and check in)

Code:

Param(
   [string]$collection,
   [string]$projectName,
   [string]$token
)
$uri="$collection/$projectName/_apis/work/teamsettings/iterations?`$timeframe=current&api-version=v2.0-preview"
Write-Output $uri
$result = Invoke-RestMethod -Uri $uri -Method Get -Headers @{Authorization=("Bearer {0}" -f $token)}

Write-Output "success"
Write-Output $result.value.path

Write-Host "##vso[task.setvariable variable=currentSprint;]$($result.value.path)"
  1. Edit your build definition
  2. Click Options tab and check Allow Scripts to Access OAuth Token

enter image description here

  1. Add PowerShell build step and specify PowerShell file (step 1) (arguments: -collection $(System.TeamFoundationCollectionUri) -projectName $(System.TeamProject) -token $(System.AccessToken) )

enter image description here

After that, the current sprint value is stored in currentSprint variable.