首页 > 解决方案 > 通过 Jenkins 运行 powershell 脚本时出现此错误:“NativeCommandError”不确定如何使用调用命令

问题描述

在 Windows PowerShell (ISE) 中忽略错误级别!= 0

我已阅读此链接,但不确定如何运行“调用命令”,我的 $ErrorActionPreference 为“继续”。

这是我得到的错误:

06:06:55 + & powershell -NoProfile -NonInteractive -ExecutionPolicy Bypass -Command '& ''E: ...
06:06:55 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
06:06:55 + CategoryInfo : NotSpecified: (root : 2020-10-...something:String) [], RemoteException
06:06:55 + FullyQualifiedErrorId : NativeCommandError

标签: powershellerror-handlinginvoke-command

解决方案


$errorActionPreference应该在脚本块中定义,例如:

Invoke-Command {$ErrorActionPreference = 'SilentlyContinue'; REST OF THE CODE}

推荐阅读