Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
799 views
in Technique[技术] by (71.8m points)

java - Using OpenJDK 14 in Jenkins

Is it possible to use OpenJDK-14 in Jenkins (Docker version)? I set the version in the Configurations by unpacking the JDK from this link: https://download.java.net/openjdk/jdk14/ri/openjdk-14+36_linux-x64_bin.tar.gz

This is my Jenkinsfile:

pipeline {
    agent any
    tools {
        jdk 'jdk-14'
        maven 'Maven-3-6-3'
    }
    stages {
        stage("build project") {
            steps {
                sh 'java -version'
                echo 'building project...'
                sh 'mvn clean install'
            }
        }
    }
}

This is the error i get:

  • mvn clean install 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

Also the sh 'java -version' command, still gives me this:

  • java -version openjdk version "1.8.0_242" OpenJDK Runtime Environment (build 1.8.0_242-b08) OpenJDK 64-Bit Server VM (build 25.242-b08, mixed mode)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Generally, you can install the "Jenkins AdoptOpenJDK installer Plugin"

Then in your Global Tool Configuration | Add JDK (${JENKINSURL}/configureTools/), you will

  • Add JDK
  • tick install automatically
  • Delete Installer (thereby removing the default Oracle installer)
  • Add Installer
  • Install from adoptOpenJDK.net
  • Save

If you have more than one JDK installed, in your jobs, you should now have an option to choose JDK or specify in the pipeline tools section.

Alternatively, you can just specify the path to where JDK14 is installed beforehand instead of dynamically installing.

It would seem you have the "installed beforehand" part done, but are missing the Global tool configuration, setting the path for jdk-14, so it's not overriding the SYSTEM default.

JDK Global tool config

(obviously, pick from drop down or set path).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...