问题描述
在使用 Jenkins 时遇到了一个问题,Jenkins 无法读取 config.xml
文件,报错信息如下:
java.io.EOFException: no more data available - expected end tag </hudson> to close start tag <hudson> from line 2, parser stopped on END_TAG seen ...<globalNodeProperties/>\n\n... @42:1 at org.xmlpull.mxp1.MXParser.fillBuf(MXParser.java:3035) at org.xmlpull.mxp1.MXParser.more(MXParser.java:3046) at org.xmlpull.mxp1.MXParser.nextImpl(MXParser.java:1384) at org.xmlpull.mxp1.MXParser.next(MXParser.java:1093) at com.thoughtworks.xstream.io.xml.XppReader.pullNextEvent(XppReader.java:109)Caused: com.thoughtworks.xstream.io.StreamException: : no more data available - expected end tag </hudson> to close start tag <hudson> from line 2, parser stopped on END_TAG seen ...<globalNodeProperties/>\n\n... @42:1 at com.thoughtworks.xstream.io.xml.XppReader.pullNextEvent(XppReader.java:126) at com.thoughtworks.xstream.io.xml.AbstractPullReader.readRealEvent(AbstractPullReader.java:148) at com.thoughtworks.xstream.io.xml.AbstractPullReader.readEvent(AbstractPullReader.java:135) at com.thoughtworks.xstream.io.xml.AbstractPullReader.hasMoreChildren(AbstractPullReader.java:87) at com.thoughtworks.xstream.io.ReaderWrapper.hasMoreChildren(ReaderWrapper.java:32) at hudson.util.RobustReflectionConverter.doUnmarshal(RobustReflectionConverter.java:309) at hudson.util.RobustReflectionConverter.unmarshal(RobustReflectionConverter.java:270) at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:72)Caused: com.thoughtworks.xstream.converters.ConversionException: : no more data available - expected end tag </hudson> to close start tag <hudson> from line 2, parser stopped on END_TAG seen ...<globalNodeProperties/>\n\n... @42:1 : : no more data available - expected end tag </hudson> to close start tag <hudson> from line 2, parser stopped on END_TAG seen ...<globalNodeProperties/>\n\n... @42:1---- Debugging information ----message : : no more data available - expected end tag </hudson> to close start tag <hudson> from line 2, parser stopped on END_TAG seen ...<globalNodeProperties/>\n\n... @42:1cause-exception : com.thoughtworks.xstream.io.StreamExceptioncause-message : : no more data available - expected end tag </hudson> to close start tag <hudson> from line 2, parser stopped on END_TAG seen ...<globalNodeProperties/>\n\n... @42:1class : hudson.model.Hudsonrequired-type : hudson.model.Hudsonconverter-type : hudson.util.RobustReflectionConverterpath : /hudsonline number : 42version : not available------------------------------- at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:79) at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:65) at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66) at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:50) at com.thoughtworks.xstream.core.TreeUnmarshaller.start(TreeUnmarshaller.java:134) at com.thoughtworks.xstream.core.AbstractTreeMarshallingStrategy.unmarshal(AbstractTreeMarshallingStrategy.java:32) at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1189) at hudson.util.XStream2.unmarshal(XStream2.java:114) at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1173) at hudson.XmlFile.unmarshal(XmlFile.java:160)Caused: java.io.IOException: Unable to read /var/lib/jenkins/config.xml at hudson.XmlFile.unmarshal(XmlFile.java:162) at jenkins.model.Jenkins.loadConfig(Jenkins.java:3078) at jenkins.model.Jenkins.access$1200(Jenkins.java:307) at jenkins.model.Jenkins$16.run(Jenkins.java:3096) at org.jvnet.hudson.reactor.TaskGraphBuilder$TaskImpl.run(TaskGraphBuilder.java:169) at org.jvnet.hudson.reactor.Reactor.runTask(Reactor.java:282) at jenkins.model.Jenkins$7.runTask(Jenkins.java:1090) at org.jvnet.hudson.reactor.Reactor$2.run(Reactor.java:210) at org.jvnet.hudson.reactor.Reactor$Node.run(Reactor.java:117) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748)Caused: org.jvnet.hudson.reactor.ReactorException at org.jvnet.hudson.reactor.Reactor.execute(Reactor.java:269) at jenkins.InitReactorRunner.run(InitReactorRunner.java:47) at jenkins.model.Jenkins.executeReactor(Jenkins.java:1124) at jenkins.model.Jenkins.<init>(Jenkins.java:929) at hudson.model.Hudson.<init>(Hudson.java:86) at hudson.model.Hudson.<init>(Hudson.java:82) at hudson.WebAppMain$3.run(WebAppMain.java:235)Caused: hudson.util.HudsonFailedToLoad at hudson.WebAppMain$3.run(WebAppMain.java:252)</code></pre>
解决方案
请注意以下操作可能会因版本差异而有所不同,请做好备份工作。
方案1
检查并修复配置文件的语法错误
1. 停止 Jenkins 服务:
shell
service jenkins stop
2. 将 JENKINS_HOME/config.xml
文件备份:
shell
mv JENKINS_HOME/config.xml JENKINS_HOME/config.xml_bak
3. 启动 Jenkins 服务:
shell
service jenkins start
方案2
使用 XML 校验工具检查 XML 标签的平衡性
1. 使用第三方的 XML 校验工具来检查配置文件 config.xml
是否有未平衡的 XML 标签。
2. 根据校验结果修复配置文件中的 XML 标签错误。
以上两种方案中,方案1适
正文完