3

我们将 PowerShell 用于我们的一些自动构建脚本。不幸的是,默认情况下,PowerShell 会在出错后继续运行。

通常,我可以通过设置来改变这种行为$ErrorActionPreference = Stop

我看不到对应的命令行开关PowerShell.exe,我们(故意)用 运行命令-noprofile,所以我不能把它放在那里。

如何为构建脚本执行此操作?

4

2 回答 2

2

似乎没有办法设置:

powershell -erroractionpreference stop ...

以下将起作用:

powershell -command { $ErrorActionPreference = "stop"; .\test.ps1 } -noprofile

当然没有什么可以阻止脚本(重新)设置 ErrorActionPreference。

于 2012-11-16T15:25:16.750 回答
2

把它放在你正在运行的脚本的顶部?

$ErrorActionPreference = 'Stop'

或者,您也可以使用 ErrorAction 参数在 cmdlet 级别获得类似的控制。

于 2012-11-16T15:04:42.567 回答