0
votes

We are trying to add a current sprint as tag to last commit of the respective sprint. For that I have written a powershell script..Am able to get a current sprint value as output and am able to tag the commit with build number but couldnt able to tag this current sprint value as tag.Please find the code below and suggest

$uri="$(System.TeamFoundationCollectionUri)$(System.TeamProject)/_apis/work/teamsettings/iterations?timeframe=current&api-version=5.1"
$result = Invoke-RestMethod -Uri $uri -Method Get -Headers @{Authorization="Bearer 
$(System.AccessToken)" }
Write-Output $result.value.name  //Here its printing current sprint number
Write-Output "success"
Write-Output $result.value.path
Write-Host "##vso[task.setvariable variable=currentSprint]$result.value.name"
Write-Host "##vso[build.addbuildtag]"  //Here its adding build number as tag

Any ideas to pass that sprint number to this tag???

1

1 Answers

0
votes

Powershell is not expanding the value and name properties of $version inside your string. To resolve this, assign the results to a variable before passing inside your VSO string.

$uri="$(System.TeamFoundationCollectionUri)$(System.TeamProject)/_apis/work/teamsettings/iterations?timeframe=current&api-version=5.1"
$result = Invoke-RestMethod -Uri $uri -Method Get -Headers @{Authorization="Bearer 
$(System.AccessToken)" }
Write-Output $result.value.name 
$sprintNumber = $result.value.name
Write-Output "success"
Write-Output $result.value.path
Write-Host "##vso[task.setvariable variable=currentSprint]$sprintNumber"
Write-Host "##vso[build.addbuildtag]"