2

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 Answer 1

8

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Any chance we could get as intrinsic variable so I can make the build number include the sprint name - at the moment I have to update a variable every iteration to keep them in step

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.