Pipeline how to prepare environment params by groovy scripts

166 views
Skip to first unread message

Torsten Reinhard

unread,
Dec 7, 2016, 11:12:25 AM12/7/16
to Jenkins Users
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



Reply all
Reply to author
Forward
0 new messages