4

我正在尝试从 Jenkins 运行 PowerShell 脚本,但它似乎完全忽略了执行策略!这可以通过直接执行 powershell.exe 或使用PowerShell 插件来实现

附加信息:

Jenkins 作为 Windows 服务运行(使用本地系统帐户,非交互式)。连接到该服务器并检查执行策略确实是RemoteSigned

PS C:\> whoami
nt authority\system

PS C:\> Get-ExecutionPolicy
RemoteSigned
PS C:\>

但是,在运行 Jenkins 构建时,情况并非如此。Get-ExecutionPolicy -List这是在构建步骤中执行的输出:

d:\workspace\test-job>powershell Get-ExecutionPolicy -list 
  Scope                         ExecutionPolicy
  -----                         ---------------
  MachinePolicy                 Undefined
  UserPolicy                    Undefined
  Process                       Undefined
  CurrentUser                   Undefined
  LocalMachine                  Undefined

我还尝试从构建步骤中明确设置它,没有。

我错过了什么?

4

1 回答 1

11

拉了两个多小时的头发,问题是x86/x64!!!

事实证明,Set-ExecutionPolicyx64(默认)PowerShell 对 x86 设置没有影响!

Jenkins 是一个 32 位进程,从 Windows 服务运行 - 它执行 x86 PowerShell!

此外,x86 PowerShell 的 Modules 目录位于 下%systemroot%\SysWow64\WindowsPowerShell\1.0\Modules,这是另一个要记住的重要事实!

于 2014-07-02T12:58:00.393 回答