gpt4 book ai didi

java - Jenkins作业找不到JDK但Jenkins中配置了JDK

转载 作者:行者123 更新时间:2023-12-01 18:27:41 25 4
gpt4 key购买 nike

我一直在尝试在 Jenkins 上创建测试作业,但出现 JRE 错误。想法很简单:

1)job将运行一个简单的测试命令“mvn clean test”2)Allure报告插件会根据测试结果生成测试。

我无法获得 Jenkins 作业生成的结果。

但是,当我在命令行上运行“mvn clean test”命令时。我没有收到任何错误,测试结果已生成。当我运行以下管道时,我可以看到 maven 和 JDK 路径是正确的。

node('master') {
stage ('Run tests')
dir ('C:/Program Files (x86)/Jenkins/ProjectDirectory') {
try {
bat '''mvn -version'''
}
catch (Exception ex) { currentBuild.result = 'UNSTABLE' }
finally {
stage ('Publish report')
step([$class: 'AllureReportPublisher', includeProperties: false, jdk: 'jdk-1.8', results: [[path: '/target/surefire-reports']]])
}
}
}

输出:

C:\Program Files (x86)\Jenkins\ProjectDirectory>mvn -version 
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: C:\3rd_party\apache-maven-3.6.3\bin\..
Java version: 1.8.0_191, vendor: Oracle Corporation, runtime: C:\Program Files (x86)\Java\jre1.8.0_191
Default locale: en_US, platform encoding: Cp1252
OS name: "windows server 2016", version: "10.0", arch: "x86", family: "windows"

如果我在 Jenkins 管道中运行测试,则会收到以下错误。

[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.942 s
[INFO] Finished at: 2020-02-07T14:51:07Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.6.1:testCompile (default-testCompile) on project restassuredcourse: Compilation failure
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?

我在管理 Jenkins > 配置系统中有正确的 JDK 路径。 enter image description here

如果我在 Jenkins 管道中执行“mvn -version”。我可以看到Jenkins机器可以访问正确的路径。

最佳答案

在我的本地 Jenkins 上,我没有在 Jenkins 配置中声明任何 JDK。

尝试在 Jenkins 配置中删除 JDK,Jenkins 将使用操作系统中的 JAVA_HOME 路径。

关于java - Jenkins作业找不到JDK但Jenkins中配置了JDK,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60206277/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com