为什么Jenkins即使在工具中配置了openjdk-17.0.5之后仍指向旧的JDK?

kcrjzv8t  于 2022-11-21  发布在  Jenkins
关注(0)|答案(1)|浏览(169)

我在docker中运行Jenkins 2.345作为容器。主机操作系统是ubuntu 20.04 LTS。现在,我想编译一个需要Java 17的maven项目,为此我在Jenkins中安装了***JDK 17作为工具***。现在,为了验证新的JDK是否工作,我运行以下管道。
管道脚本

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
                '''
            }
        }
    }
}

构建管道后,我得到了以下输出日志。

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

因此,即使更新了JAVA_HOME值,Jenkins仍只能识别***/opt/java/openjdk/bin***中的*java,这是默认设置。
那么,有人能确定Jenkins出了什么问题,为什么会出现这个问题吗?

5uzkadbs

5uzkadbs1#

只需在docker中配置jenkins代理,并使用任何包含java 17的docker映像作为代理。如何实现-请查看此处https://www.youtube.com/watch?v=ymI02j-hqpU

相关问题