Reputation: 1359
I thought that a call to ##vso[task.complete result=Failed;] should make the script step where it is called fail immediately but I have now seen one case in my pipeline where this is not the case.
Is my assumption wrong or there a bug in the Azure pipelines script task?
My build agent is running the task in an Ubuntu Container and the agent itself is a Linux agent.
Upvotes: 8
Views: 8081
Reputation: 4689
Use PowerShell and Write-Output for your desired behavior in Azure DevOps
- powershell: |
Write-Host "##[error] Something went wrong"
Write-Output "##vso[task.complete result=Failed;]Finished"
Upvotes: 0
Reputation: 1
Check if there is a try-catch around the line of exiting the script.
It took me a whole day why it was showing an error but the task would never be marked as failure.
If there is no try-catch around the exit or [system.environment]::Exit(1) line it should work..
Upvotes: 0
Reputation: 1359
I just made a small test and using below code leads to the desired goal of aborting the step with an error but showing only one error message in the Azure pipelines web ui:
echo "##vso[task.logissue type=error]Something went very wrong."
echo "##vso[task.complete result=Failed;]Make step fail"
exit 0
This is working fine but it looks really ugly since the "exit 0" gives the impression that the step is ok but actually the status will be "Failed" because of the task.complete call.
Still I would like to know if this behaviour of the task.complete command to not abort the step is "by design" or I just found a workaround for a bug.
Upvotes: 2
Reputation: 13554
You can try to add the command line 'exit 1
' after the '##vso[task.complete result=Failed;]
' command.
echo "##vso[task.complete result=Failed;]"
exit 1
Similarly, you also can try using the logging command 'LogIssue' in your pipeline task to log an error on the task.
echo "##vso[task.logissue type=error]Something went very wrong."
exit 1
Upvotes: 5