我正在尝试从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
我也尝试从构建步骤中明确设置它,没有.
我错过了什么?
经过两个多小时拉我的头发,问题是x86/x64!
原来,Set-ExecutionPolicy
x64(默认)PowerShell对x86设置没有影响!
Jenkins是一个32位进程,从Windows服务运行 - 它执行x86 PowerShell!
另外,x86 PowerShell的Modules目录位于%systemroot%\SysWow64\WindowsPowerShell\1.0\Modules
另一个重要的事实要记住!