当使用 -File 参数调用 PowerShell 时,即使发生错误也会返回 0 退出代码。这意味着我的构建状态变成了绿色,但实际上应该是失败的 :(
例如:
(在 wtf.ps1 中)
$ErrorActionPreference = "Stop";
$null.split()
(cmd)
powershell -file c:\wtf.ps1
You cannot call a method on a null-valued expression.
At C:\wtf.ps1:3 char:12
+ $null.split <<<< ()
+ CategoryInfo : InvalidOperation: (split:String) [], ParentConta
insErrorRecordException
+ FullyQualifiedErrorId : InvokeMethodOnNull
echo %errorlevel%
0
powershell c:\wtf.ps1
You cannot call a method on a null-valued expression.
At C:\wtf.ps1:3 char:12
+ $null.split <<<< ()
+ CategoryInfo : InvalidOperation: (split:String) [], ParentConta
insErrorRecordException
+ FullyQualifiedErrorId : InvokeMethodOnNull
echo %errorlevel%
1
有什么想法吗?
(我已经尝试了这个链接的前两页中几乎所有的想法:https://www.google.co.uk/search?q=powershell+file+argument+exit+code)