Jenkins execute PowerShell scripts

丶灬走出姿态 提交于 2020-01-14 10:33:11

问题


I'm trying to run PowerShell scripts from Jenkins, but it seems to completely ignore the execution policy! This happens either by executing powershell.exe directly, or using the PowerShell plugin

Additional information:

Jenkins is running as a Windows Service (using the Local System account, non-interactive). Connecting to that server, and checking execution policy is indeed RemoteSigned:

PS C:\> whoami
nt authority\system

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

However, when running a Jenkins build, this is not the case. Here's the output of executing Get-ExecutionPolicy -List inside a build step:

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

I also tried setting it explicitly from the build step, nothing.

What am I missing?


回答1:


After more than two hours of pulling my hair, the problem was x86/x64!!!

Turns out, Set-ExecutionPolicy of x64 (default) PowerShell has no effect on the x86 settings!

Jenkins is a 32-bit process, running from a Windows service - it executes the x86 PowerShell!

In addition, the Modules directory for x86 PowerShell is located under %systemroot%\SysWow64\WindowsPowerShell\1.0\Modules, another important fact to remember!



来源:https://stackoverflow.com/questions/24529789/jenkins-execute-powershell-scripts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!