4

Jenkins

Installed from docker image jenkinsci/docker - README.me

Plugins

Pipeline Maven Plugin

configureTools

  1. JDK :
  2. Maven :
    • name : Default
    • install automatically : true (Install from Apache)
    • version : 3.6.0

Jenkinsfile

pipeline {
    agent any

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

Error

[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] }

Question
What I don't understand is why the $JAVA_HOME is incorrect ? (should be /var/jenkins_home/tools/hudson.model.JDK/Java_10/jdk-10.0.2, no ?)
I've try to set it on the global properties of the jenkins system configuration, but I've get the same output/error (and don't want to set it here as there can be other java_home for other java installation)
What am I missing ?


EDIT Opened an issue to Jenkins (Jira - JENKINS-54959)


EDIT 2
After some discussion with the Jenkins crews, we finally found the missing option. As the archive contains a subdirectory (here jdk-10.0.2), we need to inform the de-zipper with the subdir field

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

so now, I got the error

[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] }

LE GALL Benoît
  • 7,159
  • 1
  • 36
  • 48
  • According to [this blog about declarative maven project](https://jenkins.io/blog/2017/02/07/declarative-maven-project/) I found via [this answer](https://stackoverflow.com/a/43254747/201725) to a related question you should have a `tools` section in the pipeline stating you want to use the tools. It is common to have many tools, but only use a few in each pipeline, so you have to tell it. – Jan Hudec Nov 30 '18 at 08:59
  • 1
    shouldn't need to declare ``tools`` section as I'm using withMaven (I added the plugin on the description) But I've tried (in case of), but same error, the ``JAVA_HOME`` is still incomplete – LE GALL Benoît Nov 30 '18 at 13:50

2 Answers2

2

This seems to work if you set the "Subdirectory of extracted archive" of the JDK configuration:

workaround1

Bruno Medeiros
  • 2,251
  • 21
  • 34
  • 1
    What version of Jenkins were you running? I have `Jenkins ver. 2.204.2` and when checking the box `Install automatically` and clicking options from drop-down (i.e. Extract *.zip, etc.) does not show other fields. – Raf Feb 06 '20 at 15:50
0

OK,

by installing the Java 11 Support Preview is available in Jenkins 2.155+ I'm not anymore having the java error \o/

I'm closing this problem :)

LE GALL Benoît
  • 7,159
  • 1
  • 36
  • 48