-
Bug
-
Resolution: Fixed
-
Major
-
None
-
Jenkins 2.49, Pipeline-Groovy Plugin 2.29 and everything related also latest versions
My goal was to create some abstractions in shared (global pipeline) library so that in the Jenkinsfile I only have the configuration of the build, whereas the re-usable build script logic is fully in the library; so very much like the Section https://jenkins.io/doc/book/pipeline/shared-libraries/#defining-a-more-structured-dsl.
In the shared library I use simple class inheritance, but the call to a super method fails with CpsCallableInvocation.
This is the stacktrace:
hudson.remoting.ProxyException: org.codehaus.groovy.runtime.InvokerInvocationException: com.cloudbees.groovy.cps.impl.CpsCallableInvocation at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:100) at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1218) at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.superCall(DefaultInvoker.java:29) at com.acme.B1.build(file:/var/lib/jenkins/jobs/Pipeline-Using-Shared-Library/builds/187/libs/******-shared-library/src/com/acme/B1.groovy:21) at acme.b1(/var/lib/jenkins/jobs/Pipeline-Using-Shared-Library/builds/187/libs/******-shared-library/vars/acme.groovy:9) at WorkflowScript.run(WorkflowScript:18) at ___cps.transform___(Native Method) at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:54) at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:109) at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixArg(FunctionCallBlock.java:82) at sun.reflect.GeneratedMethodAccessor273.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72) at com.cloudbees.groovy.cps.impl.ClosureBlock.eval(ClosureBlock.java:46) at com.cloudbees.groovy.cps.Next.step(Next.java:74) at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:154) at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$001(SandboxContinuable.java:18) at org.jenkinsci.plugins.workflow.cps.SandboxContinuable$1.call(SandboxContinuable.java:33) at org.jenkinsci.plugins.workflow.cps.SandboxContinuable$1.call(SandboxContinuable.java:30) at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovySandbox.runInSandbox(GroovySandbox.java:108) at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:30) at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:165) at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:328) at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$100(CpsThreadGroup.java:80) at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:240) at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:228) at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:64) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:112) at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) Caused by: hudson.remoting.ProxyException: com.cloudbees.groovy.cps.impl.CpsCallableInvocation at sun.reflect.GeneratedConstructorAccessor549.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.AbstractCallSite.callConstructor(AbstractCallSite.java:263) at com.acme.B1.build(B1.groovy) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93) at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1218) at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.superCall(DefaultInvoker.java:29) ... 29 more
This is the build console output, before the aforementioned problem:
[Pipeline] echo Pipeline Script using shared library [Pipeline] echo from Jenkinsfile via "acme.b0" [Pipeline] echo from C1.build: name from Jenkinsfile via "acme.c1" [Pipeline] End of Pipeline // And then would be the aforementioned stacktrace output
And at long last, this is the code:
#!/usr/bin/env groovy echo 'Pipeline Script using shared library' @Library('******-shared-library@branches/*************') _ acme.b0 { echo 'from Jenkinsfile via "acme.b0"' } acme.c1 { name = 'name from Jenkinsfile via "acme.c1"' } // This does not work: acme.b1 { name = 'name from Jenkinsfile via "acme.b1"' }
#!/usr/bin/env groovy void b0(Closure body) { def b0 = new com.acme.B0() b0.build(body) } void b1(Closure configBody) { def b1 = new com.acme.B1(this) b1.build(configBody) } void c1(Closure configBody) { def c1 = new com.acme.C1(this) c1.build(configBody) }
#!/usr/bin/env groovy package com.acme class B0 implements Serializable { public void build(Closure body) { body() } }
#!/usr/bin/env groovy package com.acme class B1 extends B0 { def script B1(def script) { this.script = script } public void build(Closure configBody) { // First evaluate the body configuration block, and collect configuration into the object: def config = [:] configBody.resolveStrategy = Closure.DELEGATE_FIRST configBody.delegate = config configBody() // Then build, based on the configuration provided: super.build() { // !!! This is line #21 where the problem occurs script.echo "from B1.build: ${config.name}" } } }
#!/usr/bin/env groovy package com.acme class C1 implements Serializable { def script def acme C1(def script) { this.script = script this.acme = script.acme } public void build(Closure configBody) { // First evaluate the body configuration block, and collect configuration into the object: def config = [:] configBody.resolveStrategy = Closure.DELEGATE_FIRST configBody.delegate = config configBody() // Then build, based on the configuration provided: acme.b0 { script.echo "from C1.build: ${config.name}" } } }
Please mind: In this case the approach via acme.c1 and com.acme.C1 calling acme.b0 step is the workaround for the problem...
- is related to
-
JENKINS-45982 Calling super to CPS-transformed methods fails with CpsCallableInvocation
- Resolved
- links to