Using OpenJDK 14 in Jenkins

ⅰ亾dé卋堺 提交于 2021-01-29 15:20:27

问题


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)

回答1:


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.

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



来源:https://stackoverflow.com/questions/64977072/using-openjdk-14-in-jenkins

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!