forked from PowerShell/vscode-powershell
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfindPsesBuild.ps1
27 lines (22 loc) · 1.23 KB
/
findPsesBuild.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
$branch = [uri]::EscapeDataString($env:PSES_BRANCH)
$headers = @{Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN"}
$buildsUrl = $env:VSTS_PSES_URL_TEMPLATE -f $branch, "succeeded"
$succeededBuilds = Invoke-RestMethod -ContentType application/json -Uri $buildsUrl -Headers $headers
Write-Host "Requested URL: $buildsUrl"
Write-Host "Got response:`n$(ConvertTo-Json $succeededBuilds)"
$buildsURL = $buildsURL -replace "branchName", "tagName"
$taggedBuilds = Invoke-RestMethod -ContentType application/json -Uri $buildsUrl -Headers $headers
Write-Host "Requested URL: $buildsUrl"
Write-Host "Got response:`n$(ConvertTo-Json $taggedBuilds)"
$buildsUrl = $env:VSTS_PSES_URL_TEMPLATE -f $branch, "partiallySucceeded"
$partiallySucceededBuilds = Invoke-RestMethod -ContentType application/json -Uri $buildsUrl -Headers $headers
Write-Host "Requested URL: $buildsUrl"
Write-Host "Got response:`n$(ConvertTo-Json $partiallySucceededBuilds)"
$builds = @(
$succeededBuilds.value
$taggedBuilds.value
$partiallySucceededBuilds.value
) | Sort-Object finishTime -Descending
Write-Host "Got PSES_BRANCH: ${env:PSES_BRANCH}"
Write-Host "setting PSES_BUILDID to $($builds[0].Id)"
Write-Host "##vso[task.setvariable variable=PSES_BUILDID]$($builds[0].Id)"