通过 powershell 将错误传达给 azure pipeline 的方法有哪些?

What are the ways in which one can communicate error to the azure pipeline via powershell?

假设我正在使用 Powershell 脚本任务执行一些复杂的事情,我想让 azure 管道知道这些错误。

我知道使用 exit(0) 是成功的,任何非零退出都是失败,这将导致 azure 管道任务失败(除非启用错误时继续)。

第二种方法是使用与上面相同的写入错误。

第三种方法是使用 write-error 通过 powershell 将输出发送到 stderr,然后在 azure 管道任务上将 'Fail on standard error' 设置为 true(复选标记)。这种方法可以单独使用,也可以与上述两种方法一起使用。

还有其他我遗漏的方法吗?

如果您使用 Write-Error,即使 标准错误失败 未选中,任务也会失败。

另一种选择是使用 logging command task.logissue:

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

结果: