Docker Jenkins - 自动安装的 Maven + Open Java 无法协同工作

Docker Jenkins - Automatically installed Maven + Open Java not working together

詹金斯

从 docker 图像安装 jenkinsci/docker - README.me

插件

Pipeline Maven Plugin

配置工具

  1. JDK :
  2. 行家:
    • 名称:默认值
    • 自动安装:true(从 Apache 安装)
    • 版本:3.6.0

詹金斯文件

pipeline {
    agent any

    stages {
        stage('Clean') {
            steps {
                withMaven(maven: 'Default',jdk: 'Java 10') {
                    sh "echo JAVA_HOME=$JAVA_HOME"
                    sh "mvn clean"
                }
            }
        }
    }
}

错误

[Pipeline] // stage
[Pipeline] withEnv
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Clean)
[Pipeline] withMaven
[withMaven] Options: []
[withMaven] Available options:
[withMaven] using JDK installation Java 10
[withMaven] using Maven installation 'Default' [Pipeline] {
[Pipeline] sh
+ echo 'JAVA_HOME=/var/jenkins_home/tools/hudson.model.JDK/Java_10'
JAVA_HOME=/var/jenkins_home/tools/hudson.model.JDK/Java_10
[Pipeline] sh
+ mvn clean -B -V
----- withMaven Wrapper script -----
The JAVA_HOME environment variable is not defined correctly
This environment variable is needed to run this program
NB: JAVA_HOME should point to a JDK not a JRE
[Pipeline] }

问题
我不明白的是为什么 $JAVA_HOME 不正确? (应该是/var/jenkins_home/tools/hudson.model.JDK/Java_10/jdk-10.0.2,不是吗?)
我尝试在 jenkins 系统配置的全局属性上设置它,但我得到了相同的 output/error(并且不想在这里设置它,因为可以有其他 java_home其他 java 安装)
我错过了什么?


编辑 向 Jenkins 提出问题 (Jira - JENKINS-54959)


编辑 2
在与 Jenkins 工作人员讨论后,我们终于找到了缺失的选项。 由于存档包含一个子目录(这里是 jdk-10.0.2),我们需要用子目录字段

通知解压器

Optional subdirectory of the downloaded and unpacked archive to use as the tool's home directory

所以现在,我得到了错误

[Pipeline] withMaven
[withMaven] Options: []
[withMaven] Available options: [withMaven] using JDK installation Java 10
[withMaven] using Maven installation 'Default'
[Pipeline] {
[Pipeline] sh
+ echo 'JAVA_HOME=/var/jenkins_home/tools/hudson.model.JDK/Java_10/jdk-10.0.2'
JAVA_HOME=/var/jenkins_home/tools/hudson.model.JDK/Java_10/jdk-10.0.2
[Pipeline] sh
+ mvn clean -B -V
----- withMaven Wrapper script -----
/var/jenkins_home/tools/hudson.tasks.Maven_MavenInstallation/Default/bin/mvn: exec: line 199: /var/jenkins_home/tools/hudson.model.JDK/Java_10/jdk-10.0.2/bin/java: not found
[Pipeline] }

好的,

通过安装 Java 11 Support Preview is available in Jenkins 2.155+ 我不再有 java 错误 \o/

我正在关闭这个问题:)

如果您设置 JDK 配置的 "Subdirectory of extracted archive",这似乎有效: