Hi,
in my old builds jobs I often prepared some environment parameters, based on groovy code.
For example I extracted some attribute values from an existing *.xml file:
def appServerCluster = new XmlSlurper().parse( myXmlFileAtURI )
// SSHParams is a simple Serializable Wrapper to encapsulate some values
SSHParams params = new SSHParams(appServerCluster)
return [ unixuser: params.unixuser,
dir: params.dir,
hostname: params.hostname ]
How does this approach look like now - using cps-workflow-libs ?
I couldn´t find a standard step and I also couldn´t get the shown code running.
A simple Testpipeline looked like:
What I got was instead was :
- a hanging job
- a job terminating with
com.cloudbees.groovy.cps.impl.CpsCallableInvocation
at sun.reflect.GeneratedConstructorAccessor905.newInstance(Unknown 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.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:263)
at com.mycompany.SSHParams.setUnixuser(SSHParams.groovy)
at com.mycompany.SSHParams$setUnixuser.callCurrent(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:52)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:154)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:166)
at com.mycompany.SSHParams.<init>(SSHParams.groovy:56)
=> What is "best practice" to transform the old code - and to get pipeline code running without CPS errors ?
Thanx in advance,
Torsten