If I try to read an xml file within a pipeline with XmlSluper:
String versionPrefix = this.adaptVersionPrefix(releasePrefix)
String nexusUrl = "${env.NEXUS_BASE_URL}/service/local/repositories/${repository}/content/${group.replaceAll('\\.','/') + '/' + artifact}/maven-metadata.xml"
URL metadataUrl = new URL(nexusUrl)
URLConnection connection = metadataUrl.openConnection()
if (connection.responseCode == 404) {
// returned all the first time
return versionPrefix + '1'
} elseif (connection.responseCode == 200) {
String xmlContent = connection.content.text
def metadata = new XmlSlurper().parseText(xmlContent)
List<Integer> maxVersion = []
for (GPathResult pathResult : metadata.'versioning'.'versions'.'version') {
if (pathResult.toString().startsWith(versionPrefix)) {
maxVersion << Integer.valueOf(pathResult.text() - versionPrefix)
}
}
if (maxVersion.isEmpty()) {
// only one by new release
return versionPrefix + '1'
} else {
return versionPrefix + (maxVersion.sort().last() + 1);
}
} else {
thrownew Exception("Unknown response code (${connection.responseCode}) from nexus url ${nexusUrl}. Exit job...")
}
an error is thrown:
javax.xml.parsers.FactoryConfigurationError: Provider for class javax.xml.parsers.SAXParserFactory cannot be created
at javax.xml.parsers.FactoryFinder.findServiceProvider(FactoryFinder.java:311)
at javax.xml.parsers.FactoryFinder.find(FactoryFinder.java:267)
at javax.xml.parsers.SAXParserFactory.newInstance(SAXParserFactory.java:127)
at groovy.xml.FactorySupport$2.run(FactorySupport.java:58)
at java.security.AccessController.doPrivileged(Native Method)
at groovy.xml.FactorySupport.createFactory(FactorySupport.java:35)
at groovy.xml.FactorySupport.createSaxParserFactory(FactorySupport.java:56)
at groovy.util.XmlSlurper.<init>(XmlSlurper.java:128)
at groovy.util.XmlSlurper.<init>(XmlSlurper.java:114)
at groovy.util.XmlSlurper.<init>(XmlSlurper.java:101)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:83)
at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:105)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:60)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:235)
at org.kohsuke.groovy.sandbox.impl.Checker$3.call(Checker.java:194)
at org.kohsuke.groovy.sandbox.GroovyInterceptor.onNewInstance(GroovyInterceptor.java:40)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onNewInstance(SandboxInterceptor.java:128)
at org.kohsuke.groovy.sandbox.impl.Checker$3.call(Checker.java:191)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedConstructor(Checker.java:188)
at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.constructorCall(SandboxInvoker.java:20)
at Script1.getArtifactBuildVersion(Script1.groovy:129)
at WorkflowScript.run(WorkflowScript:34)
at ___cps.transform___(Native Method)
at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:96)
at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixName(FunctionCallBlock.java:77)
at sun.reflect.GeneratedMethodAccessor373.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
at com.cloudbees.groovy.cps.impl.ConstantBlock.eval(ConstantBlock.java:21)
at com.cloudbees.groovy.cps.Next.step(Next.java:58)
at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:154)
at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$001(SandboxContinuable.java:18)
at org.jenkinsci.plugins.workflow.cps.SandboxContinuable$1.call(SandboxContinuable.java:33)
at org.jenkinsci.plugins.workflow.cps.SandboxContinuable$1.call(SandboxContinuable.java:30)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovySandbox.runInSandbox(GroovySandbox.java:108)
at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:30)
at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:163)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:328)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$100(CpsThreadGroup.java:80)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:240)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:228)
at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:63)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:112)
at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.RuntimeException: Provider for class javax.xml.parsers.SAXParserFactory cannot be created
at javax.xml.parsers.FactoryFinder.findServiceProvider(FactoryFinder.java:308)
at javax.xml.parsers.FactoryFinder.find(FactoryFinder.java:267)
at javax.xml.parsers.SAXParserFactory.newInstance(SAXParserFactory.java:127)
at groovy.xml.FactorySupport$2.run(FactorySupport.java:58)
at java.security.AccessController.doPrivileged(Native Method)
at groovy.xml.FactorySupport.createFactory(FactorySupport.java:35)
at groovy.xml.FactorySupport.createSaxParserFactory(FactorySupport.java:56)
at groovy.util.XmlSlurper.<init>(XmlSlurper.java:128)
at groovy.util.XmlSlurper.<init>(XmlSlurper.java:114)
at groovy.util.XmlSlurper.<init>(XmlSlurper.java:101)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:83)
at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:105)
The error line 131 looks like:
def metadata = new XmlSlurper().parseText(xmlContent)
After long investigation of the problem, I've found finally the cause of the error. It is the JaCoCo Plugin. If the plugin is installed and active the error occurs.
If I try to read an xml file within a pipeline with XmlSluper:
{code} String versionPrefix = this.adaptVersionPrefix(releasePrefix) String nexusUrl = "${env.NEXUS_BASE_URL}/service/local/repositories/${repository}/content/${group.replaceAll('\\.','/') + '/' + artifact}/maven-metadata.xml" URL metadataUrl = new URL(nexusUrl) URLConnection connection = metadataUrl.openConnection() if (connection.responseCode == 404) { // returned all the first time return versionPrefix + '1' } else if (connection.responseCode == 200) { String xmlContent = connection.content.text
def metadata rootNode = new XmlSlurper().parseText(xmlContent) List<Integer> maxVersion = [] for (GPathResult pathResult : metadata.'versioning'.'versions'.'version') {<root> if (pathResult.toString().startsWith(versionPrefix)) { maxVersion <a>one!< Integer.valueOf(pathResult.text() - versionPrefix)/a> } } if (maxVersion.isEmpty()) { <a>two!< // only one by new releasea> return versionPrefix + </root> '1'' ) } else { return versionPrefix + (maxVersion assert rootNode.sort()a.lastsize() + 1); == 2
} } else { throw new Exception("Unknown response code (${connection.responseCode}) from nexus url ${nexusUrl}. Exit job...") } {code}
an error is thrown:
{code} javax.xml.parsers.FactoryConfigurationError: Provider for class javax.xml.parsers.SAXParserFactory cannot be created at javax.xml.parsers.FactoryFinder.findServiceProvider(FactoryFinder.java:311) at javax.xml.parsers.FactoryFinder.find(FactoryFinder.java:267) at javax.xml.parsers.SAXParserFactory.newInstance(SAXParserFactory.java:127) at groovy.xml.FactorySupport$2.run(FactorySupport.java:58) at java.security.AccessController.doPrivileged(Native Method) at groovy.xml.FactorySupport.createFactory(FactorySupport.java:35) at groovy.xml.FactorySupport.createSaxParserFactory(FactorySupport.java:56) at groovy.util.XmlSlurper.<init>(XmlSlurper.java:128) at groovy.util.XmlSlurper.<init>(XmlSlurper.java:114) at groovy.util.XmlSlurper.<init>(XmlSlurper.java:101)
at sun.reflect.NativeConstructorAccessorImplGeneratedConstructorAccessor408.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:83) at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:105) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:60) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:235) at org.kohsuke.groovy.sandbox.impl.Checker$3.call(Checker.java:194) at org.kohsuke.groovy.sandbox.GroovyInterceptor.onNewInstance(GroovyInterceptor.java:40) at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onNewInstance(SandboxInterceptor.java:128) at org.kohsuke.groovy.sandbox.impl.Checker$3.call(Checker.java:191) at org.kohsuke.groovy.sandbox.impl.Checker.checkedConstructor(Checker.java:188) at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.constructorCall(SandboxInvoker.java:20) at
Script1.getArtifactBuildVersion(Script1.groovy:129) at WorkflowScript.run(WorkflowScript:3433)
at ___cps.transform___(Native Method) at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:96) at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixName(FunctionCallBlock.java:77)
at sun.reflect.GeneratedMethodAccessor373GeneratedMethodAccessor518.invoke(Unknown Source)
at sun.reflect.NativeConstructorAccessorImplGeneratedConstructorAccessor408.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:83) at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:105)
{code} at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:60) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:235) The error line 131 looks like at org.kohsuke.groovy.sandbox.impl.Checker$3.call(Checker.java:194) {code} at org.kohsuke.groovy.sandbox.GroovyInterceptor.onNewInstance(GroovyInterceptor.java:40) def metadata = new XmlSlurper at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onNewInstance(SandboxInterceptor.java:128) at org.parseTextkohsuke.groovy.sandbox.impl.Checker$3.call(xmlContentChecker.java:191)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedConstructor(Checker.java:188) at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.constructorCall(SandboxInvoker.java:20)
... 28 more Caused by: java.util.ServiceConfigurationError: javax.xml.parsers.SAXParserFactory: Provider org.apache.xerces.jaxp.SAXParserFactoryImpl not a subtype at java.util.ServiceLoader.fail(ServiceLoader.java:239) at java.util.ServiceLoader.access$300(ServiceLoader.java:185) at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:376) at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:404) at java.util.ServiceLoader$1.next(ServiceLoader.java:480) at javax.xml.parsers.FactoryFinder$1.run(FactoryFinder.java:294) at java.security.AccessController.doPrivileged(Native Method) at javax.xml.parsers.FactoryFinder.findServiceProvider(FactoryFinder.java:289) ... 50 more
{code}
Even if I try only to initialize the XmlSluper class, the same error is thrown
After long investigation of the problem, I've found finally the cause of the error. It is the [JaCoCo Plugin|https://wiki.jenkins-ci.org/display/JENKINS/JaCoCo+Plugin]. If the plugin is installed and active actived the error occurs.
After long investigation of the problem, I've found finally the cause of the error. It is the [JaCoCo Plugin|https://wiki.jenkins-ci.org/display/JENKINS/JaCoCo+Plugin]. If the plugin is installed and actived activated the error occurs.
jacoco.hpi includes WEB-INF/lib/xercesImpl-2.9.1.jar and WEB-INF/lib/xml-apis-1.0.b2.jar, which is unnecessary and harmful. Please set up <excludes> in your POM and review bundled JARs—there are far too many and most are likely unused.
That said, be advised that use of XmlSlurper and similar utilities from Pipeline script is not supported. Perform any such processing outside of Jenkins, in sh/bat steps.