The following powershell script will get the current sprint name of the team in a project, we can use the same or other REST API in VSTS pipeline.
Param
(
[string] $vstsAccount = "girishgoudar",
[string] $projectName = "PritiX.Assignment.Exam.Demo",
[string] $teamName = "PritiX.Assignment.Exam.Demo%20Team",
[string] $token = "icww3qhmyrcbdgs3zeuwgcss24pk5tbsuni3zmkfhxugdkv3i63q" #personal Access token PAT
)
$results = @{}
if(!$vstsAccount.ToLower().Contains(".visualstudio.com")) {$vstsAccount+=".visualstudio.com"}
if(!$vstsAccount.ToLower().StartsWith("https://")) {$vstsAccount = "https://"+$vstsAccount}
if(!$vstsAccount.EndsWith("/")) {$vstsAccount+="/"}
# Only current iteration of the team
$uri = "$($vstsAccount)DefaultCollection/$($projectName)/$($teamName)/_apis/work/TeamSettings/Iterations?`$timeframe=current&api-version=2.0"
# Calls VSTS REST API
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))
$results = Invoke-RestMethod -Uri $uri -Method Get -ContentType "application/json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}
# Test for results
if ($results.count -eq 0)
{
throw "Results not found"
}
Write-Host $results.value[0].name
Write-Host $results.value[0].url
No comments:
Post a Comment