简体   繁体   English

Jenkins执行PowerShell脚本

[英]Jenkins execute PowerShell scripts

I'm trying to run PowerShell scripts from Jenkins, but it seems to completely ignore the execution policy! 我正在尝试从Jenkins运行PowerShell脚本,但它似乎完全忽略了执行策略! This happens either by executing powershell.exe directly, or using the PowerShell plugin 这可以通过直接执行powershell.exe或使用PowerShell插件来实现

Additional information: 附加信息:

Jenkins is running as a Windows Service (using the Local System account, non-interactive). Jenkins作为Windows服务运行(使用本地系统帐户,非交互式)。 Connecting to that server, and checking execution policy is indeed RemoteSigned : 连接到该服务器,并检查执行策略确实是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. 但是,在运行Jenkins构建时,情况并非如此。 Here's the output of executing Get-ExecutionPolicy -List inside a build step: 这是在构建步骤中执行Get-ExecutionPolicy -List的输出:

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? 我错过了什么?

After more than two hours of pulling my hair, the problem was x86/x64!!! 经过两个多小时拉我的头发,问题是x86 / x64!

Turns out, Set-ExecutionPolicy of x64 (default) PowerShell has no effect on the x86 settings! 事实证明,x64的Set-ExecutionPolicy (默认)PowerShell对x86设置没有影响!

Jenkins is a 32-bit process, running from a Windows service - it executes the x86 PowerShell! Jenkins是一个32位进程,从Windows服务运行 - 它执行x86 PowerShell!

In addition, the Modules directory for x86 PowerShell is located under %systemroot%\\SysWow64\\WindowsPowerShell\\1.0\\Modules , another important fact to remember! 此外,x86 PowerShell的Modules目录位于%systemroot%\\SysWow64\\WindowsPowerShell\\1.0\\Modules ,这是另一个需要记住的重要事实!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM