Groovy DSL arguments

56 views
Skip to first unread message

Paul Allen

unread,
Jun 24, 2016, 8:39:31 AM6/24/16
to Jenkins Developers, Jesse Glick
Hi Devs, Jesse,

I have written two DSL functions ‘p4fetch’ and ‘p4save’ (extending AbstractStepImpl). The ‘p4fetch’ DSL returns a Map<String, Object> object which I can print out and modify. e.g:

def client = p4fetch id: 'test-001', type: 'client'
echo "client: ${client}"

def host = client.get('Host')
echo "host: ${host}”


Result:

client: [Owner:pallen, Description:Created by pallen, Host:pallen-mac.local, SubmitOptions:submitunchanged, Update:2014/05/27 20:12:12, Options:noallwrite noclobber nocompress unlocked nomodtime normdir, LineEnd:local, specFormatted:, Root:/Users/pallen/workspace, View0://depot/test/... //test/foo/..., Access:2014/05/29 11:14:09, Client:test]

host: pallen-mac.local



The second function ‘p4save’ was designed to save the changes, by taking the ‘client’ (a Map<String, Object> object) as a parameter. e.g.

def result = p4save spec: client, type: 'client'


However this throws a 'cannot be cast to java.lang.Class’ exception (see below), is there any way I can pass the object back into the DSL with out using the [$class …] notation?


Kind regards,
Paul





java.lang.ClassCastException: sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl cannot be cast to java.lang.Class
at org.jenkinsci.plugins.workflow.structs.DescribableHelper.coerce(DescribableHelper.java:214)
at org.jenkinsci.plugins.workflow.structs.DescribableHelper.buildArguments(DescribableHelper.java:186)
at org.jenkinsci.plugins.workflow.structs.DescribableHelper.instantiate(DescribableHelper.java:91)
at org.jenkinsci.plugins.workflow.steps.StepDescriptor.newInstance(StepDescriptor.java:95)
at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:133)
at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:100)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:45)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.methodCall(DefaultInvoker.java:15)
at WorkflowScript.run(WorkflowScript:31)
at Unknown.Unknown(Unknown)
at ___cps.transform___(Native Method)
at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:69)
at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:106)
at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixArg(FunctionCallBlock.java:79)
at sun.reflect.GeneratedMethodAccessor144.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
at com.cloudbees.groovy.cps.impl.CollectionLiteralBlock$ContinuationImpl.dispatch(CollectionLiteralBlock.java:55)
at com.cloudbees.groovy.cps.impl.CollectionLiteralBlock$ContinuationImpl.item(CollectionLiteralBlock.java:45)
at sun.reflect.GeneratedMethodAccessor143.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
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:145)
at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:164)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:268)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$000(CpsThreadGroup.java:71)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:177)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:175)
at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:47)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:111)
at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Finished: FAILURE

Jesse Glick

unread,
Jun 24, 2016, 2:11:23 PM6/24/16
to Jenkins Developers
On Fri, Jun 24, 2016 at 8:39 AM, Paul Allen <pallen...@gmail.com> wrote:
> java.lang.ClassCastException: sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl cannot be cast to java.lang.Class
> at org.jenkinsci.plugins.workflow.structs.DescribableHelper.coerce(DescribableHelper.java:214)

Probably JENKINS-28510. Generally speaking, Pipeline steps are not
designed to take arbitrary data types as parameters, only things which
Jenkins databinding handles: primitives, `Describable`s, and
`List`s/arrays of the above.

Robert Sandell

unread,
Jun 27, 2016, 5:29:42 AM6/27/16
to jenkin...@googlegroups.com
Well I have something similar that works for me. But it's just one of the parameters that is a map and I had to do custom instance creation.

/B


--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CANfRfr1ipk2j6AL%2B1Zwfa2Oy1fL4fUMNNqpqVApFd6PsDsT0GA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.



--
Robert Sandell
Software Engineer
CloudBees Inc.

Jesse Glick

unread,
Jun 28, 2016, 12:21:50 PM6/28/16
to Jenkins Dev
Yes, you would need to override `newInstance`, and _Snippet Generator_
or reference documentation are still going to choke on it.
Reply all
Reply to author
Forward
0 new messages