Jenkins powershell plugin is running 32 bit Powershell and I need 64bit

前端 未结 4 991
花落未央
花落未央 2020-12-03 18:56

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:

[Env         


        
4条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-03 19:13

    Environment

    • Jenkins on Windows (mine happens to run as a service)
    • plus Powershell plugin (for running Powershell scripts as "build steps")

    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.

    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
    

    Solution

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

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

    First, install chocolatey:

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

    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).

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

    choco install -y javaruntime
    

    Or:

    choco install -y jre8
    

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

    Changed:

    %BASE%\jre\bin\java
    

    To (set the path as appropriate for your instance):

    C:\Program Files\Java\jre1.8.0_66\bin\java
    

    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:

    C:\ProgramData\Oracle\Java\javapath\java.exe
    

    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.

    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

提交回复
热议问题