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

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

问题描述

我对 Jenkins 中的 powershell 集成非常陌生,我的脚本无法运行,因为(我相信)我需要在 64 位中执行 powershell.运行:

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 上的 Jenkins(我的恰好作为服务运行)
  • 加上 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.但是,executor/slave 进程必须运行 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:WindowsTEMPhudson123456789.ps1'"
      
      C:Windowssystem32;C:Windows;C:WindowsSystem32WindowsPowerShellv1.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:WindowsTEMPhudson123456789.ps1:7 char:1
      

      <小时>

      解决方案

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

      我使用 Chocolatey 通过管理员"PowerShell 安装了一个相当新的 JRE:

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

      首先,安装巧克力:

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

      寻找可用的最新版本https://chocolatey.org/packages?q=java (chocolatey 有多个包用于同一件事,通常不会完全更新).

      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 编号较大的那个):

      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%jreinjava</executable>
      

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

      <executable>C:Program FilesJavajre1.8.0_66injava</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:ProgramDataOracleJavajavapathjava.exe</executable>
      

      然后我重新启动了詹金斯.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天全站免登陆