heremaps/gradle-jenkins-jobdsl-plugin

XML 1.1 breaks seed job

UnsafePointer opened this issue · 3 comments

Under some plugin configuration (still looking into this) the generated XML has version 1.1. The XML parser used in the seed job breaks with this. As there aren't many differences between XML 1.1 and 1.0, we're working around this by patching the generated XML files.

Opened an issue now that I have a stacktrace:

00:00:24.791 Create local XML dir '/tmp/seedjob-396'
00:00:24.793 Copy remote files to local XML dir
00:00:24.837 Start updating jobs from local XML dir
00:00:24.840 Processing sdk
00:00:24.841   Update item sdk
00:00:24.848 FATAL: Unable to read /var/lib/jenkins/jobs/sdk/atomic4708471507247466491.tmp
00:00:24.849 org.xmlpull.v1.XmlPullParserException: only 1.0 is supported as <?xml version not '1.1' (position: START_DOCUMENT seen <?xml version="1.1"... @1:19) 
00:00:24.849 	at org.xmlpull.mxp1.MXParser.parseXmlDeclWithVersion(MXParser.java:2608)
00:00:24.849 	at org.xmlpull.mxp1.MXParser.parseXmlDecl(MXParser.java:2592)
00:00:24.849 	at org.xmlpull.mxp1.MXParser.parsePI(MXParser.java:2466)
00:00:24.849 	at org.xmlpull.mxp1.MXParser.parseProlog(MXParser.java:1447)
00:00:24.849 	at org.xmlpull.mxp1.MXParser.nextImpl(MXParser.java:1395)
00:00:24.849 	at org.xmlpull.mxp1.MXParser.next(MXParser.java:1093)
00:00:24.849 	at com.thoughtworks.xstream.io.xml.XppReader.pullNextEvent(XppReader.java:109)
00:00:24.849 Caused: com.thoughtworks.xstream.io.StreamException:  : only 1.0 is supported as <?xml version not '1.1' (position: START_DOCUMENT seen <?xml version="1.1"... @1:19) 
00:00:24.849 	at com.thoughtworks.xstream.io.xml.XppReader.pullNextEvent(XppReader.java:124)
00:00:24.849 	at com.thoughtworks.xstream.io.xml.AbstractPullReader.readRealEvent(AbstractPullReader.java:148)
00:00:24.849 	at com.thoughtworks.xstream.io.xml.AbstractPullReader.readEvent(AbstractPullReader.java:141)
00:00:24.849 	at com.thoughtworks.xstream.io.xml.AbstractPullReader.move(AbstractPullReader.java:118)
00:00:24.849 	at com.thoughtworks.xstream.io.xml.AbstractPullReader.moveDown(AbstractPullReader.java:103)
00:00:24.849 	at com.thoughtworks.xstream.io.xml.XppReader.<init>(XppReader.java:63)
00:00:24.849 	at com.thoughtworks.xstream.io.xml.AbstractXppDriver.createReader(AbstractXppDriver.java:54)
00:00:24.849 	at com.thoughtworks.xstream.io.xml.AbstractXppDriver.createReader(AbstractXppDriver.java:65)
00:00:24.849 	at hudson.XmlFile.unmarshal(XmlFile.java:167)
00:00:24.849 Caused: java.io.IOException: Unable to read /var/lib/jenkins/jobs/sdk/atomic4708471507247466491.tmp
00:00:24.849 	at hudson.XmlFile.unmarshal(XmlFile.java:169)
00:00:24.849 	at hudson.model.AbstractItem.updateByXml(AbstractItem.java:772)
00:00:24.849 	at hudson.model.AbstractItem.updateByXml(AbstractItem.java:749)
00:00:24.849 	at hudson.model.AbstractItem$updateByXml$0.call(Unknown Source)
00:00:24.849 	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
00:00:24.849 	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
00:00:24.849 	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
00:00:24.849 	at Script1.updateItem(Script1.groovy:36)
00:00:24.849 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
00:00:24.849 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
00:00:24.849 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
00:00:24.849 	at java.lang.reflect.Method.invoke(Method.java:498)
00:00:24.849 	at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
00:00:24.849 	at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
00:00:24.849 	at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:384)
00:00:24.849 	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022)
00:00:24.849 	at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:69)
00:00:24.849 	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:52)
00:00:24.849 	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:154)
00:00:24.849 	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:182)
00:00:24.849 	at Script1$_updateJobs_closure1.doCall(Script1.groovy:106)
00:00:24.849 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
00:00:24.849 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
00:00:24.849 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
00:00:24.849 	at java.lang.reflect.Method.invoke(Method.java:498)
00:00:24.849 	at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
00:00:24.849 	at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
00:00:24.849 	at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:294)
00:00:24.849 	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022)
00:00:24.849 	at groovy.lang.Closure.call(Closure.java:414)
00:00:24.849 	at groovy.lang.Closure.call(Closure.java:430)
00:00:24.849 	at org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:2040)
00:00:24.849 	at org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:2025)
00:00:24.849 	at org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:2066)
00:00:24.849 	at org.codehaus.groovy.runtime.dgm$162.invoke(Unknown Source)
00:00:24.849 	at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoMetaMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:274)
00:00:24.849 	at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:56)
00:00:24.849 	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
00:00:24.849 	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
00:00:24.849 	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
00:00:24.849 	at Script1.updateJobs(Script1.groovy:83)
00:00:24.849 	at Script1.updateJobs(Script1.groovy)
00:00:24.849 	at Script1$updateJobs.callCurrent(Unknown Source)
00:00:24.849 	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:52)
00:00:24.849 	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:154)
00:00:24.849 	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:166)
00:00:24.849 	at Script1.run(Script1.groovy:136)
00:00:24.849 	at groovy.lang.GroovyShell.evaluate(GroovyShell.java:585)
00:00:24.849 	at groovy.lang.GroovyShell.evaluate(GroovyShell.java:623)
00:00:24.849 	at groovy.lang.GroovyShell.evaluate(GroovyShell.java:594)
00:00:24.849 	at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SecureGroovyScript.evaluate(SecureGroovyScript.java:343)
00:00:24.849 	at hudson.plugins.groovy.SystemGroovy.run(SystemGroovy.java:95)
00:00:24.849 	at hudson.plugins.groovy.SystemGroovy.perform(SystemGroovy.java:59)
00:00:24.849 	at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
00:00:24.849 	at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:744)
00:00:24.849 	at hudson.model.Build$BuildExecution.build(Build.java:206)
00:00:24.849 	at hudson.model.Build$BuildExecution.doRun(Build.java:163)
00:00:24.849 	at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:504)
00:00:24.849 	at hudson.model.Run.execute(Run.java:1724)
00:00:24.849 	at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
00:00:24.849 	at hudson.model.ResourceController.execute(ResourceController.java:97)
00:00:24.849 	at hudson.model.Executor.run(Executor.java:421)

Can it be related to the gradle version? I had similar problem "org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 20; XML version "1.1" is not supported, only XML 1.0 is supported". I fixed it by update gradle plugin to the version 4.7.

How you patching the generated xmls? As far as I know dslUpdateJenkins generate temp xmls and delete them after execution.

This shouldn't be due to the Gradle version, since the XML is generated by the Jenkins libraries themselves.

I did an upgrade to Gradle 4.10.2 (we were on 4.3) to try it out. Still getting the same XML prologs with version="1.1".

We're using the dslGenerateXml task for our Seed jobs and then apply the XMLs using the Jenkins Groovy API. So we can patch the XML files with sed after generating them. Not a pretty solution but works for now.

I tried the Seed job on our current Jenkins (2.138.2, LTS from 2018-10-10) and loading the un-patched XML files worked fine. So I guess the issue was caused by the JobDSL plugin requiring a higher version of Jenkins.

I'll do some more checks on that. But guess we can address this bug by putting up a notice about the minimal Jenkins version required for Job DSL.

XML 1.1 was introduced in Jenkins v2.105 on 2018-02-04: https://jenkins.io/changelog/#v2.105