Jenkins执行PowerShell脚本 [英] Jenkins execute PowerShell scripts

查看:332
本文介绍了Jenkins执行PowerShell脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

其他信息:

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

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:\>

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

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.

我想念什么?

推荐答案

拉了两个多小时后,问题出在x86/x64上!

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

结果是,x64的Set-ExecutionPolicy(默认)PowerShell对x86设置没有影响!

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

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

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

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

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

这篇关于Jenkins执行PowerShell脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆