@@ -113,10 +113,13 @@ try {
113113 $installations = @ ()
114114 $page = 1
115115 do {
116- $pageInstallations = @ (Invoke-RestMethod `
116+ # Assign the response before wrapping it in @(). PowerShell otherwise
117+ # preserves a top-level JSON array as one nested pipeline object.
118+ $pageResponse = Invoke-RestMethod `
117119 - Uri " https://api.github.com/app/installations?per_page=100&page=$page " `
118120 - Headers $headers `
119- - Method Get)
121+ - Method Get
122+ $pageInstallations = @ ($pageResponse )
120123 $installations += $pageInstallations
121124 $page ++
122125 } while ($pageInstallations.Count -eq 100 )
@@ -125,12 +128,19 @@ catch {
125128 Write-PipelineTelemetryError - Category ' Build' - Message " Failed to list GitHub App installations: $_ . The signed JWT may be invalid or the App's Client ID ('$AppClientId ') may be incorrect."
126129 exit 1
127130}
128- $installation = $installations | Where-Object { $_.account.login -ieq $InstallationOwner } | Select-Object - First 1
129- if (-not $installation ) {
131+ $matchingInstallations = @ ( $installations | Where-Object { $_.account.login -ieq $InstallationOwner })
132+ if ($matchingInstallations .Count -eq 0 ) {
130133 $found = ($installations | ForEach-Object { $_.account.login }) -join ' , '
131134 Write-PipelineTelemetryError - Category ' Build' - Message " No installation found for '$InstallationOwner '. App is installed on: $found "
132135 exit 1
133136}
137+ if ($matchingInstallations.Count -ne 1 ) {
138+ $matchingIds = ($matchingInstallations | ForEach-Object { $_.id }) -join ' , '
139+ Write-PipelineTelemetryError - Category ' Build' - Message " Found multiple installations for '$InstallationOwner ': $matchingIds "
140+ exit 1
141+ }
142+ $installation = $matchingInstallations [0 ]
143+ Write-Host " Using installation $ ( $installation.id ) for '$ ( $installation.account.login ) '."
134144
135145try {
136146 $tokenResponse = Invoke-RestMethod `
0 commit comments