NonCPS not working properly?

44 views
Skip to first unread message

Torsten Reinhard

unread,
Jan 25, 2017, 11:16:03 AM1/25/17
to Jenkins Users
Hi,

I put that (tested) one-liner for converting a xml to a Map to a @NonCPS funkction

@NonCPS
def readXml( String xml ) {
   
return new XmlSlurper().parseText(xml).children().collectEntries { n-> [(n.name()):{->n.children()?.collectEntries(owner)?:n.text()}()]}
}



When using it inside a pipeline script like:

node {
    stage
('Checkout configuration') {
     
...
   
     
String xml = readFile("path/to/myfile.xml" )
     
def root = readXml ( xml )
}



it´s telling me:


hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No signature of method: groovy.util.slurpersupport.NodeChildren.collectEntries() is applicable for argument types: (WorkflowScript$_readXml_closure1) values: [WorkflowScript$_readXml_closure1@35ff77c8]
        at org
.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:55)
        at org
.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:51)
        at org
.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
        at org
.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
        at org
.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
        at
WorkflowScript.readXml(WorkflowScript:9)

Any ideas? The readXml(...) function is working when used outside of Jenkins workflow-cps-plugin

Best regards, Torsten

Reply all
Reply to author
Forward
0 new messages