|
| 1 | +[CmdletBinding(PositionalBinding=$false)] |
| 2 | +param ( |
| 3 | + [string]$accessToken, |
| 4 | + [string]$buildId, |
| 5 | + [string]$insertionDir |
| 6 | +) |
| 7 | + |
| 8 | +Set-StrictMode -version 2.0 |
| 9 | +$ErrorActionPreference = "Stop" |
| 10 | + |
| 11 | +try { |
| 12 | + # build map of all *.vsman files to their `info.buildVersion` values |
| 13 | + $manifestVersionMap = @{} |
| 14 | + Get-ChildItem -Path "$insertionDir\*" -Filter "*.vsman" | ForEach-Object { |
| 15 | + $manifestName = Split-Path $_ -Leaf |
| 16 | + $vsmanContents = Get-Content $_ | ConvertFrom-Json |
| 17 | + $buildVersion = $vsmanContents.info.buildVersion |
| 18 | + $manifestVersionMap.Add($manifestName, $buildVersion) |
| 19 | + } |
| 20 | + |
| 21 | + # find all publish URLs |
| 22 | + $manifests = @() |
| 23 | + $seenManifests = @{} |
| 24 | + $url = "https://dev.azure.com/dnceng/internal/_apis/build/builds/$buildId/logs?api-version=5.1" |
| 25 | + $base64 = [Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$accessToken")) |
| 26 | + $headers = @{ |
| 27 | + Authorization = "Basic $base64" |
| 28 | + } |
| 29 | + Write-Host "Fetching log from $url" |
| 30 | + $json = Invoke-WebRequest -Method Get -Uri $url -Headers $headers -UseBasicParsing | ConvertFrom-Json |
| 31 | + foreach ($l in $json.value) { |
| 32 | + $logUrl = $l.url |
| 33 | + Write-Host "Fetching log from $logUrl" |
| 34 | + $log = (Invoke-WebRequest -Method Get -Uri $logUrl -Headers $headers -UseBasicParsing).Content |
| 35 | + If ($log -Match "(https://vsdrop\.corp\.microsoft\.com/[^\r\n;]+);([^\r\n]+)\r?\n") { |
| 36 | + $manifestShortUrl = $Matches[1] |
| 37 | + $manifestName = $Matches[2] |
| 38 | + $manifestUrl = "$manifestShortUrl;$manifestName" |
| 39 | + If (-Not $seenManifests.Contains($manifestUrl)) { |
| 40 | + $seenManifests.Add($manifestUrl, $true) |
| 41 | + $buildVersion = $manifestVersionMap[$manifestName] |
| 42 | + $manifestEntry = "$manifestName{$buildVersion}=$manifestUrl" |
| 43 | + $manifests += $manifestEntry |
| 44 | + } |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + $final = $manifests -Join "," |
| 49 | + Write-Host "Setting InsertJsonValues to $final" |
| 50 | + Write-Host "##vso[task.setvariable variable=InsertJsonValues]$final" |
| 51 | +} |
| 52 | +catch { |
| 53 | + Write-Host $_ |
| 54 | + Write-Host $_.Exception |
| 55 | + Write-Host $_.ScriptStackTrace |
| 56 | + exit 1 |
| 57 | +} |
0 commit comments