简体   繁体   English

Jenkins Job 找不到 JDK 但在 Jenkins 中配置了 JDK

[英]Jenkins Job Can't find JDK but JDK configured in Jenkins

I have been trying to create a test job on Jenkins but I've been getting JRE error.我一直在尝试在 Jenkins 上创建一个测试作业,但我遇到了 JRE 错误。 Idea is simple:想法很简单:

1)job will run a simple test command "mvn clean test" 2)Allure report plug-in will generate test based on test results. 1)job 会运行一个简单的测试命令“mvn clean test” 2)Allure 报告插件会根据测试结果生成测试。

I can't get results generated on Jenkins job.我无法在 Jenkins 工作中获得结果。

However when I run "mvn clean test" command on command line.但是,当我在命令行上运行“mvn clean test”命令时。 I don't get any errors, test results are generated.我没有收到任何错误,生成了测试结果。 I can see maven and JDK path is correct when I run following pipeline.当我运行以下管道时,我可以看到 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']]]) 
        }
    }
}

Outputs:输出:

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"

If I run tests in the Jenkins pipeline, I get following error.如果我在 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?

I have correct JDK path in Manage Jenkins > Configure System.我在管理 Jenkins > 配置系统中有正确的 JDK 路径。 在此处输入图片说明

If I execute "mvn -version" in Jenkins pipeline.如果我在 Jenkins 管道中执行“mvn -version”。 I can see Jenkins machine can access correct path.我可以看到 Jenkins 机器可以访问正确的路径。

On my local Jenkins I do not declare any JDK in the Jenkins Configurations.在我本地的 Jenkins 上,我没有在 Jenkins 配置中声明任何 JDK。

Try to remove the JDK in Jenkins Configuration and Jenkins will use the JAVA_HOME path from your operation system.尝试删除 Jenkins 配置中的 JDK,Jenkins 将使用操作系统中的 JAVA_HOME 路径。

Just to check I generated gradle.build file and instead of executing "mvn clean test" .只是为了检查我生成的 gradle.build 文件,而不是执行 "mvn clean test" 。 I used "gradlew clean test" and it worked.我使用了“gradlew clean test”并且它起作用了。 The problem is with maven but I couldn't understand why maven does not use system JDK.问题出在 maven 上,但我不明白为什么 maven 不使用系统 JDK。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM