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:

import com.mycompany.SSHParams

@NonCPS
SSHParams getSSHParams( String httpPath ) {

    def appServerCluster = new XmlSlurper().parse( httpPath )
    
    return new SSHParams(appServerCluster)
}

def params = getSSHParams( 
'https://licdci01.bmwgroup.net:7993/projects/CD/repos/deployment-configs/raw/DEV/MRP/TEST/EMEA/deploy.app.xml'
 
)
echo params.toString()

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



-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/d9ae3d76-bc14-49d9-8c99-8abe4bdbced0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to