5

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.

Marko
  • 929
  • 9
  • 27

3 Answers3

3

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
Bright Ran-MSFT
  • 5,190
  • 1
  • 5
  • 12
  • I know this already but then (your 2nd example) in the Azure Pipelines web UI you see two error messages, one for the exit 1 call (just saying "exit code was 1") and one for the logissue command that has a proper error message. Having two error messages for one error is just bad usability that I want to avoid if possible. – Marko Nov 04 '21 at 13:14
  • Hi @Marko, The logging commands can't make the script step be failed immediately. You must add the **`exit 1`** after the logging commands if you the script step to be failed immediately when logging an error with the logging commands. We no way to only use the logging commands to make the script step be failed immediately. – Bright Ran-MSFT Nov 05 '21 at 07:12
  • The logging command from my point of view does not need to make it break but the "task.complete result=failed" should be potentially doing that. As I said I have now a solution with the exit 0 but it is somehow ugly. – Marko Nov 05 '21 at 07:31
0

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.

Marko
  • 929
  • 9
  • 27
0

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..

Mike B
  • 1