Jenkins 和 Java 14、如何正确地 select 和 JDK 编译一个给定的作业?

Jenkins and Java 14, how to properly select the JDK compiler for a given job?

我发现与此相关的主题很少,但就 Java 14 和最近的 Jenkins 版本而言没有什么新内容。使 Java 14 在 Jenkins 中可用作为通过作业编译 Java 项目的选项的推荐步骤是什么?

在我当前的安装中,我找不到 Configure JDK 选项,也找不到任何下拉菜单来选择它。我也对推荐的几种不同方法感到困惑。

要使用不同的 java 版本,您需要在主 jenkins 配置菜单 "Manage jenkins" -> "Global tool configuration" -> "Add JDK" 中进行配置。您可以自动或手动安装某些版本,但是:

"Oracle Java SE 11+ is not available for business, commercial or production use without a commercial license. Public updates for Oracle Java SE 8 released after January 2019 will not be available for business, commercial or production use without a commercial license."

之后您就可以将它添加到您的工作中了。例如在声明性管道中使用“工具”步骤:

pipeline {
    agent any
    tools {
        nodejs 'java_8'
    }
    stages {
        stage ('java test') {
            steps {
                sh 'java -version'
            }
        }
    }
}