Jenkinsfile任务执行失败 [不支持的类文件主版本57]

huangapple go评论70阅读模式
英文:

Jenkinsfile task getting faild [Unsupported class file major version 57]

问题

背景:

我之前遇到了这个错误 [不支持的类文件主版本 57]

这个错误意味着我的 Java 版本与编译 Gradle 的版本不兼容。

我的 Gradle 版本是 Gradle 6.0.1,JDK 版本是 openjdk 13.0.2

所以我将 JDK 降级为 JDK 11,问题得以解决。

我能够在终端中运行任务 "./gradlew spotbugsMain",同样也可以在 Jenkins 中使用 WebUI 在 shell 命令中运行它。这个任务正常运行并成功返回结果。

现在问题出在哪里:

我现在需要使用 Jenkinsfile 来运行任务,而不是在 Jenkins 项目中使用 shell 命令。

因此我为此设置了一个 Jenkins Pipeline。

添加了我的 Jenkinsfile 并使用 Jenkins Pipeline 项目运行了这些任务。

我所有的任务都正常工作,但是 "./gradlew spotbugsMain" 仍然出现了之前的错误 [不支持的类文件主版本 57]。

我检查了我正在使用作为 shell 命令运行 spotbugs 任务的 Jenkins 项目。它之前正常工作,但是在 Pipeline 项目中的 Jenkinsfile 却出现了错误。

我还在 Jenkins 中的 "Manage Jenkins" > "Global Tool Configuration" > "JDK" > "JDK Installations" 中添加了 JDK,如下所示:

Jenkinsfile任务执行失败 [不支持的类文件主版本57]

在我的终端中 "./gradlew spotbugsMain" 运行正常。在 Jenkins Web UI 中的 Jenkins 项目中作为 shell 命令运行任务也能正常工作。但是在使用 Jenkinsfile 运行任务的 Pipeline 项目中却无法正常工作。

我的 Jenkinsfile 是:

pipeline {
    agent any
    stages {
        stage('Spotbugs') {
            steps {
                sh "./gradlew spotbugsMain"
            }
        }
    }
}

错误信息:

> Task :app:spotbugsMain FAILED
>
> FAILURE: Build failed with an exception.
>
> * What went wrong: Execution failed for task ':app:spotbugsMain'.
>
> Unsupported class file major version 57

非常感谢对这个问题的任何帮助。提前感谢。

英文:

Background:

I got this error earlier [Unsupported class file major version 57]

This error means that my version of Java is incompatible with the one with which Gradle was compiled.

My Gradle version was Gradle 6.0.1 and JDK version was openjdk 13.0.2.

So i downgrade JDK to JDK 11 and issue was resolved.

I was able to run task "./gradlew spotbugsMain" in terminal. As well as in Jenkins using WebUI in a shell command. This jobs works fine and success in return.

Now where the problem is:

I now have to run the jobs using Jenkinsfile instead of a shell command in a Jenkins Project.

So i setup a Jenkins Pipeline for this.

Added my Jenkinsfile and ran the jobs using Jenkins pipeline project.

All my jobs are working fine but "./gradlew spotbugsMain" resulting the same error as earlier [Unsupported class file major version 57]

I checked my Jenkins Project which i am using as shell command to run spotbugs task. it was working fine but Jenkinsfile in Pipeline project is giving error.

I have also added the JDK in Jenkins > Manage Jenkins > Global Tool Configuration > JDK > JDK Installations as

Jenkinsfile任务执行失败 [不支持的类文件主版本57]

"./gradlew spotbugsMain" working fine in my terminal. Also working fine using Jenkins Project in Jenkins Web UI Where i ran the job as shell command. But not working under a pipeline project which is using Jenkinsfile to run jobs.

My Jenkinsfile is:

pipeline {
    agent any
    stages {
        stage('Spotbugs') {
            steps {
                sh "./gradlew spotbugsMain"
            }
        }

    }
}

Error:

> Task :app:spotbugsMain FAILED
>
> FAILURE: Build failed with an exception.
>
> * What went wrong: Execution failed for task ':app:spotbugsMain'.
>
> Unsupported class file major version 57

Any help in this problem is appreciated in advance. Thanks

答案1

得分: 1

Sure, here's the translated content:

更新脚本如下:

pipeline {
    agent any
    tools {
        jdk 'JDK 1.7'
    } 
    stages {
        stage('Spotbugs') {
            steps {
                sh "./gradlew spotbugsMain"
            }
        }
    }
}
英文:

Update the script to this :

pipeline {
    agent any
    tools {
        jdk 'JDK 1.7'
    } 
    stages {
        stage('Spotbugs') {
            steps {
                sh "./gradlew spotbugsMain"
            }
        }

    }
}

huangapple
  • 本文由 发表于 2020年9月23日 20:49:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/64028374.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定