Ok found the problem. If you have never run a security check on the main branch, the script will fail at this line because you will get a branchnotfoundexception.
while ($retries -gt 0) {
try {
$alertsPRTarget = Invoke-WebRequest -Uri $urlTargetAlerts -Headers $headers -Method Get -ErrorAction Stop
# Success
break
}
Perhaps the catch block can be changed to skip the error? Is it possible that the target branch may not exist when the script is run from a pull request?
catch {
# No GHAzDO results on the target branch, wait and retry?
if ($_.ErrorDetails.Message.Split("`"") -contains "BranchNotFoundException") {
$retries--
if ($retries -eq 0) {
# We have retried the maximum number of times, give up
Write-Host "##vso[task.logissue type=error] We have retried the maximum number of times, give up."
throw $_
}
# Wait and then try again
Write-Host "There are no GHAzDO results on the target branch, wait and try again."
Start-Sleep -Seconds 60
}
Originally posted by Christoph Piock-Ellena (@cpiock) in #50