Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-70768

setting alternatives failed

XMLWordPrintable

    • 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
      

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

              Created:
              Updated: