diff --git a/Actions/ReadSettings/ReadSettings.ps1 b/Actions/ReadSettings/ReadSettings.ps1 index 3d8b7261a..ea0243785 100644 --- a/Actions/ReadSettings/ReadSettings.ps1 +++ b/Actions/ReadSettings/ReadSettings.ps1 @@ -133,24 +133,25 @@ try { } if ($getenvironments) { - $headers = @{ - "Authorization" = "token $token" - "Accept" = "application/vnd.github.v3+json" - } - $url = "$($ENV:GITHUB_API_URL)/repos/$($ENV:GITHUB_REPOSITORY)/environments" - try { - $environments = @($settings.Environments)+@((Invoke-WebRequest -UseBasicParsing -Headers $headers -Uri $url | ConvertFrom-Json).environments | Where-Object { - if ($includeProduction) { - $_.Name -like $getEnvironments -or $_.Name -like "$getEnvironments (Production)" - } - else { - $_.Name -like $getEnvironments -and $_.Name -notlike '* (Production)' - } - } | ForEach-Object { $_.Name }) + $environments = @() + try { + $headers = @{ + "Authorization" = "token $token" + "Accept" = "application/vnd.github.v3+json" + } + $url = "$($ENV:GITHUB_API_URL)/repos/$($ENV:GITHUB_REPOSITORY)/environments" + $environments = @((Invoke-WebRequest -UseBasicParsing -Headers $headers -Uri $url | ConvertFrom-Json).environments | ForEach-Object { $_.Name }) } catch { - $environments = @() } + $environments = @($environments+@($settings.Environments) | Where-Object { + if ($includeProduction) { + $_ -like $getEnvironments -or $_ -like "$getEnvironments (Production)" + } + else { + $_ -like $getEnvironments -and $_ -notlike '* (Production)' + } + }) if ($environments.Count -eq 1) { $environmentsJSon = "[$($environments | ConvertTo-Json -compress)]" }