• Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • openjdk-native-plugin
    • None
    • Rocky Linux 8 openjdk-native-plugin v1.6

      In Jenkins I have configured two JDKs  (JDK-17 and JDK-11 using the openjdk-native plugin.
      However when running a test pipeline  changing the JDK fails.

      The pipeline looks like this

       

       

      pipeline {
        agent any
        options {
          ansiColor('xterm')
          buildDiscarder(logRotator(numToKeepStr: '3'))
        }
        
        stages {
          stage('Check Java 17') {
            tools {
              jdk 'JDK-17'
            }    
            steps {
              echo "========================================================" 
              echo "== JDK-17"
              sh 'java -version'
            }
          }
          stage('Check Java 11') {
            tools {
              jdk 'JDK-11'
            }    
            steps {
              echo "========================================================" 
              echo "== JDK-11"
              sh 'java -version'
            }
          }
          stage('Check native Java ') {
         
            steps {
              echo "========================================================" 
              echo "== JDK native"
              sh 'java -version'
            }
          } 
        }
      }
      

       
      The console Output looks like this

      Started by user Frank Graf
      [Pipeline] Start of Pipeline
      [Pipeline] node
      Running on abmbubdlje002 in /var/lib/jenkins/agent/workspace/JDK Testdrive
      [Pipeline] {
      [Pipeline] ansiColor
      [Pipeline] {
      
      [Pipeline] stage
      [Pipeline] { (Check Java 17)
      [Pipeline] tool
      Checking OpenJDK installation...
      $ rpm -q java-17-openjdk
      java-17-openjdk-17.0.6.0.10-3.el8_7.x86_64
      Checking OpenJDK installation...
      $ rpm -q java-17-openjdk-devel
      java-17-openjdk-devel-17.0.6.0.10-3.el8_7.x86_64
      Switching to java-17-openjdk using alternatives ... 
      $ sudo alternatives --set java /usr/lib/jvm/jre-17-openjdk/bin/java
      /usr/lib/jvm/jre-17-openjdk/bin/java has not been configured as an alternative for java
      [OpenJDK ERROR] Switching OpenJDK via atlernatives to java-17-openjdk failed! /usr/bin may not exists or point to different java version!
      [Pipeline] envVarsForTool
      Checking OpenJDK installation...
      $ rpm -q java-17-openjdk
      java-17-openjdk-17.0.6.0.10-3.el8_7.x86_64
      Checking OpenJDK installation...
      $ rpm -q java-17-openjdk-devel
      java-17-openjdk-devel-17.0.6.0.10-3.el8_7.x86_64
      Switching to java-17-openjdk using alternatives ... 
      $ sudo alternatives --set java /usr/lib/jvm/jre-17-openjdk/bin/java
      /usr/lib/jvm/jre-17-openjdk/bin/java has not been configured as an alternative for java
      [OpenJDK ERROR] Switching OpenJDK via atlernatives to java-17-openjdk failed! /usr/bin may not exists or point to different java version!
      [Pipeline] withEnv
      [Pipeline] {
      [Pipeline] echo
      ========================================================
      [Pipeline] echo
      == JDK-17
      [Pipeline] sh
      + java -version
      openjdk version "17.0.6" 2023-01-17 LTS
      OpenJDK Runtime Environment (Red_Hat-17.0.6.0.10-3.el8_7) (build 17.0.6+10-LTS)
      OpenJDK 64-Bit Server VM (Red_Hat-17.0.6.0.10-3.el8_7) (build 17.0.6+10-LTS, mixed mode, sharing)
      [Pipeline] }
      [Pipeline] // withEnv
      [Pipeline] }
      [Pipeline] // stage
      [Pipeline] stage
      [Pipeline] { (Check Java 11)
      [Pipeline] tool
      Checking OpenJDK installation...
      $ rpm -q java-11-openjdk
      java-11-openjdk-11.0.18.0.10-2.el8_7.x86_64
      Checking OpenJDK installation...
      $ rpm -q java-11-openjdk-devel
      java-11-openjdk-devel-11.0.18.0.10-2.el8_7.x86_64
      Switching to java-11-openjdk using alternatives ... 
      $ sudo alternatives --set java /usr/lib/jvm/jre-11-openjdk/bin/java
      /usr/lib/jvm/jre-11-openjdk/bin/java has not been configured as an alternative for java
      [OpenJDK ERROR] Switching OpenJDK via atlernatives to java-11-openjdk failed! /usr/bin may not exists or point to different java version!
      [Pipeline] envVarsForTool
      Checking OpenJDK installation...
      $ rpm -q java-11-openjdk
      java-11-openjdk-11.0.18.0.10-2.el8_7.x86_64
      Checking OpenJDK installation...
      $ rpm -q java-11-openjdk-devel
      java-11-openjdk-devel-11.0.18.0.10-2.el8_7.x86_64
      Switching to java-11-openjdk using alternatives ... 
      $ sudo alternatives --set java /usr/lib/jvm/jre-11-openjdk/bin/java
      /usr/lib/jvm/jre-11-openjdk/bin/java has not been configured as an alternative for java
      [OpenJDK ERROR] Switching OpenJDK via atlernatives to java-11-openjdk failed! /usr/bin may not exists or point to different java version!
      [Pipeline] withEnv
      [Pipeline] {
      [Pipeline] echo
      ========================================================
      [Pipeline] echo
      == JDK-11
      [Pipeline] sh
      + java -version
      openjdk version "17.0.6" 2023-01-17 LTS
      OpenJDK Runtime Environment (Red_Hat-17.0.6.0.10-3.el8_7) (build 17.0.6+10-LTS)
      OpenJDK 64-Bit Server VM (Red_Hat-17.0.6.0.10-3.el8_7) (build 17.0.6+10-LTS, mixed mode, sharing)
      [Pipeline] }
      [Pipeline] // withEnv
      [Pipeline] }
      [Pipeline] // stage
      [Pipeline] stage
      [Pipeline] { (Check native Java )
      [Pipeline] echo
      ========================================================
      [Pipeline] echo
      == JDK native
      [Pipeline] sh
      + java -version
      openjdk version "17.0.6" 2023-01-17 LTS
      OpenJDK Runtime Environment (Red_Hat-17.0.6.0.10-3.el8_7) (build 17.0.6+10-LTS)
      OpenJDK 64-Bit Server VM (Red_Hat-17.0.6.0.10-3.el8_7) (build 17.0.6+10-LTS, mixed mode, sharing)
      [Pipeline] }
      [Pipeline] // stage
      [Pipeline] }
      
      [Pipeline] // ansiColor
      [Pipeline] }
      [Pipeline] // node
      [Pipeline] End of Pipeline
      Finished: SUCCESS
      

      The /etc/suoders.d/jenkins config is set to

      #Defaults    requiretty
      User_Alias JENKINS = jenkins
      Cmnd_Alias OPENJDK_INSTALL = /usr/sbin/alternatives, /usr/bin/yum
      

      The problem seems to be with alternatives, since even running the command as root fails

       
      DEV [root@abmbubdlje002 ~]$ sudo alternatives --set java /usr/lib/jvm/jre-11-openjdk/bin/java
      /usr/lib/jvm/jre-11-openjdk/bin/java has not been configured as an alternative for java
      DEV [root@abmbubdlje002 ~]$ alternatives --set java /usr/lib/jvm/jre-11-openjdk/bin/java
      /usr/lib/jvm/jre-11-openjdk/bin/java has not been configured as an alternative for java
      

          [JENKINS-70768] setting alternatives failed

          Frank Graf added a comment -

          Hello I played around a little more with the alternative command and got it running when I used it with the path shown in alternatives --display java

          DEV [root@abmbubdlje002 ~]$ alternatives  --set java /usr/lib/jvm/jre-11-openjdk/bin/java
          /usr/lib/jvm/jre-11-openjdk/bin/java has not been configured as an alternative for java
          DEV [root@abmbubdlje002 ~]$ alternatives  --set java /usr/lib/jvm/java-11-openjdk-11.0.18.0.10-2.el8_7.x86_64/bin/java
          DEV [root@abmbubdlje002 ~]$
          

          Frank Graf added a comment - Hello I played around a little more with the alternative command and got it running when I used it with the path shown in alternatives --display java DEV [root@abmbubdlje002 ~]$ alternatives --set java /usr/lib/jvm/jre-11-openjdk/bin/java /usr/lib/jvm/jre-11-openjdk/bin/java has not been configured as an alternative for java DEV [root@abmbubdlje002 ~]$ alternatives --set java /usr/lib/jvm/java-11-openjdk-11.0.18.0.10-2.el8_7.x86_64/bin/java DEV [root@abmbubdlje002 ~]$

          Frank Graf added a comment -

          Seams to me instead of passing openjdkPackage.getJreName() to alternatives --set you must pass the output of the 'rpm -q' command.

          Frank Graf added a comment - Seams to me instead of passing openjdkPackage.getJreName() to alternatives --set you must pass the output of the 'rpm -q' command.

          Frank Graf added a comment -

          I think the following statement should work

          sudo alternatives --set java /usr/lib/jvm/$(rpm -q java-11-openjdk)/bin/java
          

          Frank Graf added a comment - I think the following statement should work sudo alternatives --set java /usr/lib/jvm/$(rpm -q java-11-openjdk)/bin/java

          Frank Graf added a comment -

          I almost forgot to mention another problem with the plugin.
          Altough the installation of the JDK fails. The jenkins job does not fail, Instead he falls back to the default java installation and reports SUCCESS.

          Frank Graf added a comment - I almost forgot to mention another problem with the plugin. Altough the installation of the JDK fails. The jenkins job does not fail, Instead he falls back to the default java installation and reports SUCCESS.

          Julien TAHON added a comment - - edited

          Unfortunately, your PR https://github.com/jenkinsci/openJDK-native-plugin/pull/5 is not solving the issue as we get below error. 

          $() part seems to be not interpreted but I couldn't find why

          Checking OpenJDK installation...
          $ rpm -q java-17-openjdk
          java-17-openjdk-17.0.8.0.7-2.el8.x86_64
          Checking OpenJDK installation...
          $ rpm -q java-17-openjdk-devel
          java-17-openjdk-devel-17.0.8.0.7-2.el8.x86_64
          Switching to java-17-openjdk using alternatives ... 
          $ sudo alternatives --set java "/usr/lib/jvm/$(rpm -q java-17-openjdk )/bin/java"
          /usr/lib/jvm/$(rpm -q java-17-openjdk )/bin/java has not been configured as an alternative for java
          [OpenJDK ERROR] Switching OpenJDK via alternatives to java-17-openjdk failed! /usr/bin may not exists or point to different java version! 

          Julien TAHON added a comment - - edited Unfortunately, your PR https://github.com/jenkinsci/openJDK-native-plugin/pull/5 is not solving the issue as we get below error.  $() part seems to be not interpreted but I couldn't find why Checking OpenJDK installation... $ rpm -q java-17-openjdk java-17-openjdk-17.0.8.0.7-2.el8.x86_64 Checking OpenJDK installation... $ rpm -q java-17-openjdk-devel java-17-openjdk-devel-17.0.8.0.7-2.el8.x86_64 Switching to java-17-openjdk using alternatives ... $ sudo alternatives --set java "/usr/lib/jvm/$(rpm -q java-17-openjdk )/bin/java" /usr/lib/jvm/$(rpm -q java-17-openjdk )/bin/java has not been configured as an alternative for java [OpenJDK ERROR] Switching OpenJDK via alternatives to java-17-openjdk failed! /usr/bin may not exists or point to different java version!

            Unassigned Unassigned
            grafra_pass Frank Graf
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: