Home > Mobile >  Why is Jenkins pointing to old JDK even after configuring openjdk-17.0.5 in tools?
Why is Jenkins pointing to old JDK even after configuring openjdk-17.0.5 in tools?

Time:11-15

I am running Jenkins 2.345 as a container in docker. The host OS is ubuntu 20.04 LTS. Now, I want to compile a maven project that requires Java 17, for that I have installed JDK 17 in Jenkins as a tool. Now to verify whether the new JDK is working or not I am running the following pipeline.

Pipeline Script

pipeline 
{
    agent any

    tools
    {
        jdk 'openjdk-17.0.5'
        maven 'maven'
    }

    stages {
        stage('Example') {
            steps {
                sh '''
                    env | grep -e PATH -e JAVA_HOME
                    which java
                    java -version
                    mvn -v
                '''
            }
        }
    }
}

After building the pipeline I got the following output log.

  grep -e PATH -e JAVA_HOME
  env
LD_LIBRARY_PATH=/opt/java/openjdk/lib/server:/opt/java/openjdk/lib:/opt/java/openjdk/../lib
PATH=/var/jenkins_home/tools/hudson.model.JDK/openjdk-17.0.5/openjdk-17.0.5/bin:/var/jenkins_home/tools/hudson.tasks.Maven_MavenInstallation/maven/bin:/var/jenkins_home/tools/hudson.model.JDK/openjdk-17.0.5/openjdk-17.0.5/bin:/var/jenkins_home/tools/hudson.tasks.Maven_MavenInstallation/maven/bin:/opt/java/openjdk/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
JAVA_HOME=/var/jenkins_home/tools/hudson.model.JDK/openjdk-17.0.5/openjdk-17.0.5
  which java
/opt/java/openjdk/bin/java
  java -version
openjdk version "11.0.15" 2022-04-19
OpenJDK Runtime Environment Temurin-11.0.15 10 (build 11.0.15 10)
OpenJDK 64-Bit Server VM Temurin-11.0.15 10 (build 11.0.15 10, mixed mode)
  mvn -v
The JAVA_HOME environment variable is not defined correctly,
this environment variable is needed to run this program.

So even if JAVA_HOME value is updated but still Jenkins can only identify the java within /opt/java/openjdk/bin which was the default setting.

So can anyone identify what's wrong with Jenkins and why this problem is occurring?

CodePudding user response:

Just configure jenkins agents in docker and use any docker image containing java 17 as agent. How to make it - please look here https://www.youtube.com/watch?v=ymI02j-hqpU

  • Related