我们已将 Jenkins 控制器升级到在 Windows 上的 Tomcat 上运行的 2.462.2。在此过程中,我们已将所有插件升级到最新版本。升级后一切似乎都很好。后来我们还尝试从 Java JDK 11 切换到 JDK 17。一切启动正常,一切似乎都正常,但我注意到当我运行一些作业并重新启动时,历史记录不会显示新作业。当我调查时,我注意到作业下的 builds 文件夹中没有 build.xml 文件。如果我运行新作业,历史记录会显示使用较新版本号的新作业,但如果我从磁盘重新加载,该历史记录就会消失。当我切换回 JDK 11 时,该作业确实创建了 build.xml 文件,并且使用 JDK 11 运行的作业的历史记录保留在历史记录中。
尝试在 JDK 11 下运行作业,使用相同的插件成功。日志中没有什么明显的内容。最近更新了几个插件,但从 JDK 11 上运行的旧版本到 JDK 11 上运行的新版本以及 JDK 17 上的新版本,配置没有更改。
这是日志中的片段:
SEVERE [Executor #1 for WinAgent1 : executing Run_Checkmarx #19] hudson.model.Run.execute Failed to save build record
java.io.IOException: java.lang.RuntimeException: Failed to serialize hudson.model.AbstractBuild#culprits for class hudson.model.FreeStyleBuild
at hudson.XmlFile.write(XmlFile.java:223)
at hudson.model.Run.save(Run.java:2061)
at hudson.model.Run.execute(Run.java:1947)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:44)
at hudson.model.ResourceController.execute(ResourceController.java:101)
at hudson.model.Executor.run(Executor.java:446)
Caused by: java.lang.RuntimeException: Failed to serialize hudson.model.AbstractBuild#culprits for class hudson.model.FreeStyleBuild
at hudson.util.RobustReflectionConverter$2.writeField(RobustReflectionConverter.java:274)
at hudson.util.RobustReflectionConverter$2.visit(RobustReflectionConverter.java:241)
at com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider.visitSerializableFields(PureJavaReflectionProvider.java:174)
at hudson.util.RobustReflectionConverter.doMarshal(RobustReflectionConverter.java:226)
at hudson.util.RobustReflectionConverter.marshal(RobustReflectionConverter.java:163)
at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:68)
at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:59)
at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:44)
at com.thoughtworks.xstream.core.TreeMarshaller.start(TreeMarshaller.java:83)
at com.thoughtworks.xstream.core.AbstractTreeMarshallingStrategy.marshal(AbstractTreeMarshallingStrategy.java:37)
at com.thoughtworks.xstream.XStream.marshal(XStream.java:1303)
at com.thoughtworks.xstream.XStream.marshal(XStream.java:1292)
at com.thoughtworks.xstream.XStream.toXML(XStream.java:1265)
at hudson.XmlFile.write(XmlFile.java:216)
... 5 more
Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make field private static final long java.util.Collections$UnmodifiableCollection.serialVersionUID accessible: module java.base does not "opens java.util" to unnamed module @3ad497c4
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354)
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:178)
另外,请注意这是在 Windows 上。我添加了环境变量 JDK_JAVA_OPTIONS ,其值为“-add-opens java.base/java.land=ALL-UNNAMED -add-opens java.base/java.util=ALL-UNNAMED”,希望这能提供必要的 Java opts 。虽然当我运行 java -version 时似乎出现了这个错误,但在运行作业时错误仍然存在。
迁移到JDK 17后有什么需要配置的吗?我肯定错过了一些东西,但我迫切希望在 JDK 11 支持被删除的情况下解决这个问题。我感谢任何帮助,如果需要,可以发布插件列表等。
我明白了这一点。由于我们在 Windows 上将 Tomcat 作为服务运行,因此需要使用 Tomcat9w.exe 工具来管理 JDK 选项。 catalina.bat 文件中提到了这一点。在该工具中,有一个 Java 选项卡,我可以在其中添加 --add-opens 语句,我可以执行此操作。我以以下格式添加了这些:
–add-opens=java.lang=ALL-UNNAMED –add-opens=java.util=ALL-UNNAMED
完成更改并保存后,我重新启动服务并确认日志显示参数加载,我的问题现已解决。所有作业都使用 JDK17 创建 build.xml 文件,没有错误!