Jenkins 作业失败,出现错误 java.lang.NoClassDefFoundError

Jenkins job failed with error java.lang.NoClassDefFoundError

我们已安排 Jenkins Build 来创建 AWS VM,VM 已成功联机,但在归档工件时,作业失败并显示以下错误消息。

Archiving artifacts
ERROR: Step ‘Archive the artifacts’ aborted due to exception: 
java.lang.NoClassDefFoundError: Could not initialize class sun.nio.fs.LinuxNativeDispatcher
    at sun.nio.fs.LinuxUserDefinedFileAttributeView.copyExtendedAttributes(LinuxUserDefinedFileAttributeView.java:291)
    at sun.nio.fs.LinuxFileSystem.copyNonPosixAttributes(LinuxFileSystem.java:72)
    at sun.nio.fs.UnixCopyFile.copyFile(UnixCopyFile.java:267)
    at sun.nio.fs.UnixCopyFile.copy(UnixCopyFile.java:581)
    at sun.nio.fs.UnixFileSystemProvider.copy(UnixFileSystemProvider.java:253)
    at java.nio.file.Files.copy(Files.java:1274)
    at hudson.FilePath.visit(FilePath.java:2296)
    at hudson.util.DirScanner.scanSingle(DirScanner.java:44)
    at hudson.FilePath$ExplicitlySpecifiedDirScanner.scan(FilePath.java:2991)
    at hudson.FilePath.invoke(FilePath.java:2290)
    at hudson.FilePath.invoke(FilePath.java:2283)
    at hudson.FilePath.act(FilePath.java:1042)
    at hudson.FilePath.act(FilePath.java:1025)
    at hudson.FilePath.copyRecursiveTo(FilePath.java:2283)
    at jenkins.model.StandardArtifactManager.archive(StandardArtifactManager.java:61)
    at hudson.tasks.ArtifactArchiver.perform(ArtifactArchiver.java:235)
    at hudson.tasks.BuildStepCompatibilityLayer.perform(BuildStepCompatibilityLayer.java:81)
    at hudson.tasks.BuildStepMonitor.perform(BuildStepMonitor.java:20)
    at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:744)
    at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:690)
    at hudson.model.Build$BuildExecution.post2(Build.java:186)
    at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:635)
    at hudson.model.Run.execute(Run.java:1823)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
    at hudson.model.ResourceController.execute(ResourceController.java:97)
    at hudson.model.Executor.run(Executor.java:429)

导致此问题的原因是什么以及如何解决?

通过

禁用apparrmor
/etc/init.d/apparmor stop

我在 Centos7 系统中遇到了同样的问题,并解决了安装新的 jdk 并使用 /usr/sbin/alternatives --config java [=] 设置默认值 jdk 10=]

之后,重启Jenkins就可以了

在我们的例子中,这是由于更新了 openjdk 包而 Jenkins 是 运行。詹金斯重启修复了它。可能是指向当前 JVM 目录的过时符号链接造成的。

我没有改变任何东西。我刚刚重启了 Jenkins。