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 Answers
8
votes
There isn’t build-in variable to get current sprint, but you can use REST API. Steps:
- 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)"
- Edit your build definition
- Click Options tab and check Allow Scripts to Access OAuth Token
- Add PowerShell build step and specify PowerShell file (step 1) (arguments: -collection $(System.TeamFoundationCollectionUri) -projectName $(System.TeamProject) -token $(System.AccessToken) )
After that, the current sprint value is stored in currentSprint variable.