Jenkins Powershell插件正在运行32位Powershell,我需要64位 [英] Jenkins powershell plugin is running 32 bit Powershell and I need 64bit

查看:125
本文介绍了Jenkins Powershell插件正在运行32位Powershell,我需要64位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Jenkins中的Powershell集成还很陌生,并且我的脚本无法运行,因为(我相信)我需要Powershell以64位执行.正在运行:

I'm pretty new to powershell integration in Jenkins and my scripts won't run because (I believe) I need powershell to be executed in 64 bit. Running:

[Environment]::Is64BitProcess

在执行序列中的

会产生false,然后显示我使用的cmdlet(Get-WindowsFeature)被识别为cmdlet,以此类推.以某种方式执行64位Powershell脚本? 谢谢!

in my execution sequence yields false an then a cmdlet that I use (Get-WindowsFeature) is shown as not recognized as a cmdlet, etc. Any way to execute 64 bit powershell scripts? Thanks!

推荐答案

环境

  • Windows上的詹金斯(我的碰巧是作为服务运行的)
  • plus Powershell插件(用于将Powershell脚本作为构建步骤"运行)
  • Environment

    • Jenkins on Windows (mine happens to run as a service)
    • plus Powershell plugin (for running Powershell scripts as "build steps")
    • Jenkins通常会调用正确版本的powershell.exe.但是,执行程序/从属进程必须正在运行64位JRE,以便PowerShell也可以在64位模式下运行.

      Jenkins will typically call upon the correct version of powershell.exe. However, the executor/slave process must be running a 64-bit JRE so that PowerShell can also operate in 64-bit mode.

      具有以下Powershell脚本的简单测试器项目可以显示以上32位和64位性质:

      A simple tester project with the following Powershell script can show the above 32-bit vs 64-bit nature:

      $env:Path               # Path will have the right Powershell available
      [intptr]::size          # outputs: 4 = 32-bit, 8 = 64-bit
      Stop-WebAppPool FOOBAR  # fails when 32-bit, succeeds when 64-bit
      

      控制台输出示例(为清楚起见,请留空行):

      Console output example (extra blank lines for clarity):

      [Powershell Test] $ powershell.exe -NonInteractive -ExecutionPolicy ByPass "& 'C:\Windows\TEMP\hudson123456789.ps1'"
      
      C:\Windows\system32;C:\Windows;C:\Windows\System32\WindowsPowerShell\v1.0\
      
      4
      
      Stop-WebAppPool : Retrieving the COM class factory for component with CLSID 
      {688EEEE5-6A7E-422F-B2E1-6AF00DC944A6} failed due to the following error: 
      80040154 Class not registered (Exception from HRESULT: 0x80040154 
      (REGDB_E_CLASSNOTREG)).
      
      At C:\Windows\TEMP\hudson123456789.ps1:7 char:1
      


      解决方案

      tl; dr ... 安装64位JRE,并将Jenkins配置为64位.


      Solution

      tl;dr... Install 64-bit JRE, and configure Jenkins to be 64-bit.

      我使用Chocolatey通过"Administrator" PowerShell安装了相当新的JRE:

      I used chocolatey to install a fairly recent JRE, via "Administrator" PowerShell:

      首先,安装Chocolatey:

      First, install chocolatey:

      iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))
      

      寻找可用的最新版本 https://chocolatey.org/packages?q=java(巧克力对同一件事有多个包装,通常不能完全保持最新).

      Looked for the latest version available https://chocolatey.org/packages?q=java (chocolatey has multiple packages for the same thing, often not kept fully up to date).

      然后,安装JRE(使用具有较高JRE编号的JRE):

      Then, install JRE (using the one with the higher JRE number):

      choco install -y javaruntime
      

      或者:

      choco install -y jre8
      

      最后,我编辑了jenkins.xml配置,以使其可以使用64位JRE而不是内置JRE运行.

      Finally, I edited my jenkins.xml configuration so that it would run using the 64-bit JRE instead of the built-in JRE.

      已更改:

      <executable>%BASE%\jre\bin\java</executable>
      

      到(为您的实例设置适当的路径):

      <executable>C:\Program Files\Java\jre1.8.0_66\bin\java</executable>
      

      这应该是一个总是新鲜的"符号链接(由系统更新处理),该符号链接应允许您的Jenkins实例幸免于 重启和更新 事件:

      This one should be an "always fresh" symlink (handled by system updates) that ought to allow your Jenkins instance to survive Restart and Update events:

      <executable>C:\ProgramData\Oracle\Java\javapath\java.exe</executable>
      

      然后,我重新启动了Jenkins. Powershell执行唤醒了64位的能力. 注意:我使用的是一个Jenkins实例,该实例同时充当服务器"和执行从属".对于完全自主的从属服务器,我想做任何事情来使64位模式下的从属代理进程都将获得类似的成功.

      Then I restarted Jenkins. Powershell execution woke up to the might of 64-bits. Note: I am using a single Jenkins instance that does double duty as the "server" and "execution slave" at the same time. For fully autonomous slaves, I would suppose doing whatever to get the slave-agents processes in 64-bit mode would result in a similar success.

      全自动吗?根据巧克力般的"jre8"软件包文档,使用命令行开关,甚至可以使用JRE固定的目标路径,并且如果需要全自动的非交互式步骤,则可以排除32位和/或64位版本. https://chocolatey.org/packages/jre8

      Full automation? According to the chocolatey "jre8" package documentation, using command line switches, it's even be possible to force fixed destination paths for JRE, and exclude 32-bit and/or 64-bit editions, if fully automated non-interactive steps are needed. https://chocolatey.org/packages/jre8

      这篇关于Jenkins Powershell插件正在运行32位Powershell,我需要64位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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