2

Assuming I am using a Powershell script task to perform some complex things, I want to let the azure pipeline know about the errors.

I know that using exit(0) is success and any non zero exit is a failure which will cause the azure pipeline task to fail (unless continue on error is enabled).

2nd approach is to use write-error which is same as above.

3rd approach is to use write-error to send the output to the stderr via powershell and then on the azure pipeline task set 'Fail on standard error' to true (check-mark). This approach can be used on its own and also along with both the above approachs.

Are there any other ways that I am missing?

variable
  • 8,262
  • 9
  • 95
  • 215

1 Answers1

2

If you use Write-Error the task will fail even if Fail on standard error not checked.

Another option is to use alogging command task.logissue:

##vso[task.logissue type=error;sourcepath=consoleapp/main.cs;linenumber=1;columnnumber=1;code=100;]this is an error

Results:

enter image description here

enter image description here

Shayki Abramczyk
  • 36,824
  • 16
  • 89
  • 114
  • Does it mean that this is incorrect: https://stackoverflow.com/a/58621359/1779091 (It says: this means that any command that writes an error to the host causes the task to fail. Example: Write-Error "I will cause the task to fail.") – variable Oct 31 '19 at 10:20
  • Right, you can check it easily :) – Shayki Abramczyk Oct 31 '19 at 10:21
  • I have updated my question to include the correction (of write-error). Please can you tell me what exactly is the use case of "Fail on standard error" in a powershell task? Is it useful when we write-error to stderr output, instead of just write-error? – variable Oct 31 '19 at 10:24
  • @variable I didn't check it deeply :/ – Shayki Abramczyk Oct 31 '19 at 10:28