In Azure DevOps I have a task to run a PowerShell script. In certain scenarios, the script should exit with a non-0 code, causing the task to be reported as failed. However, Azure DevOps reports the task as passed regardless.
This is a problem because I have a subsequent job that should run if this job fails, but that is not happening because of the false positive.
The relevant part of the script shows that, in the case of the screenshot, an exit code of 1 was detected, which should result in the script exiting in error.
if ($exitCode -ne 0)
{
Write-Output ("[Error] Failing task since return code was {0} while expected 0." -f $exitCode)
}
exit $exitCode
The task is run as part of a deployment job, and I do have the option failOnStandardError set to true.
- task: AzurePowerShell@5
displayName: Check Function App Version
inputs:
azureSubscription: ${{ parameters.serviceConnectionName }}
scriptType: FilePath
scriptPath: ${{ parameters.scriptsArtefactPath }}/Test-FunctionAppVersion.ps1
scriptArguments: -Uri ${{ parameters.healthCheckUri }} -AuthHeaderName Authorization -AuthHeaderValue "$(healthCheckAuthHeaderValue)"
failOnStandardError: true
azurePowerShellVersion: LatestVersion
pwsh: true
How can I make Azure DevOps honour my exit codes?
