-
Bug
-
Resolution: Fixed
-
Major
-
Jenkins 2.72, Pipeline-Groovy Plugin 2.38, Pipeline Shared Groovy Libraries Plugin 2.8 and everything related also latest versions
-
-
Pipeline - April 2018
From comment for JENKINS-42563:
Only super calls to native methods were tested IIRC. Support for super calls to CPS-transformed methods is another matter entirely. Probably a subject for a separate bug report.
From original issue JENKINS-42563 (please find below a more recent update comment and a smaller reproducer without need of a shared library):
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 moreThis 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 outputAnd at long last, this is the code:
Jenkinsfile#!/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"' }vars/acme.groovy#!/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) }src/com/acme/B0.groovy#!/usr/bin/env groovy package com.acme class B0 implements Serializable { public void build(Closure body) { body() } }src/com/acme/B1.groovy#!/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}" } } }src/com/acme/C1.groovy#!/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...
Based on the minimal pipeline script example of pmilliken in JENKINS-42563 it still fails:
- Installed pipeline plugin versions:
pipeline-model-api: 1.1.9 pipeline-build-step: 2.5.1 pipeline-model-definition: 1.1.9 pipeline-milestone-step: 1.3.1 pipeline-model-declarative-agent: 1.1.1 pipeline-stage-step: 2.2 pipeline-model-extensions: 1.1.9 script-security: 1.30 workflow-aggregator: 2.5 workflow-api: 2.20 workflow-job: 2.14 workflow-support: 2.14 workflow-step-api: 2.12 workflow-basic-steps: 2.6 workflow-cps-global-lib: 2.8 workflow-cps: 2.38 blueocean: 1.1.5 blueocean-pipeline-api-impl: 1.1.5
- Pipeline code:
class A { def script2 A(script) { script2 = script } def test(script) { script.echo "In A" } def testWithoutArgs() { script2.echo "In A without args" } } class B extends A { B(script) { super(script) } def test(script) { script.echo "In B" super.test(script) } def testWithoutArgs() { script2.echo "In B without args" super.testWithoutArgs() } } node { stage('A without args') { new A(this).testWithoutArgs() } stage('A') { new A(this).test(this) } stage('B without args') { new B(this).testWithoutArgs() } stage('B') { new B(this).test(this) } }
- Build log with disabled sandbox option:
[Pipeline] node Running on master in /var/lib/jenkins/workspace/Sandbox/JENKINS-42563 [Pipeline] { [Pipeline] stage [Pipeline] { (A without args) [Pipeline] echo In A without args [Pipeline] } [Pipeline] // stage [Pipeline] stage [Pipeline] { (A) [Pipeline] echo In A [Pipeline] } [Pipeline] // stage [Pipeline] stage [Pipeline] { (B without args) [Pipeline] echo In B without args [Pipeline] } [Pipeline] // stage [Pipeline] } [Pipeline] // node [Pipeline] End of Pipeline hudson.remoting.ProxyException: com.cloudbees.groovy.cps.impl.CpsCallableInvocation at sun.reflect.GeneratedConstructorAccessor143.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.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:110) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:263) at A.testWithoutArgs(WorkflowScript) at B.super$2$testWithoutArgs(WorkflowScript) 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:1213) at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.superCall(DefaultInvoker.java:29) Caused: 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:1213) at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.superCall(DefaultInvoker.java:29) at B.testWithoutArgs(WorkflowScript:20) at WorkflowScript.run(WorkflowScript:35) 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.fixName(FunctionCallBlock.java:77) at sun.reflect.GeneratedMethodAccessor190.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.ConstantBlock.eval(ConstantBlock.java:21) at com.cloudbees.groovy.cps.Next.step(Next.java:83) at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:173) at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:162) at org.codehaus.groovy.runtime.GroovyCategorySupport$ThreadCategoryInfo.use(GroovyCategorySupport.java:122) at org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:261) at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:162) at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:174) at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:330) at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$100(CpsThreadGroup.java:82) at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:242) at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:230) 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:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748) Finished: FAILURE
- Log with enabled sandbox option:
[Pipeline] node Running on master in /var/lib/jenkins/workspace/Sandbox/JENKINS-42563 [Pipeline] { [Pipeline] stage [Pipeline] { (A without args) [Pipeline] echo In A without args [Pipeline] } [Pipeline] // stage [Pipeline] stage [Pipeline] { (A) [Pipeline] echo In A [Pipeline] } [Pipeline] // stage [Pipeline] stage [Pipeline] { (B without args) [Pipeline] echo In B without args [Pipeline] } [Pipeline] // stage [Pipeline] } [Pipeline] // node [Pipeline] End of Pipeline hudson.remoting.ProxyException: com.cloudbees.groovy.cps.impl.CpsCallableInvocation at sun.reflect.GeneratedConstructorAccessor143.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.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:110) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:263) at A.testWithoutArgs(WorkflowScript) at B.super$2$testWithoutArgs(WorkflowScript) 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:1213) at org.kohsuke.groovy.sandbox.impl.Checker$4.call(Checker.java:207) at org.kohsuke.groovy.sandbox.GroovyInterceptor.onSuperCall(GroovyInterceptor.java:49) at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onSuperCall(SandboxInterceptor.java:380) at org.kohsuke.groovy.sandbox.impl.Checker$4.call(Checker.java:204) at org.kohsuke.groovy.sandbox.impl.Checker.checkedSuperCall(Checker.java:210) at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.superCall(SandboxInvoker.java:24) Caused: 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:1213) at org.kohsuke.groovy.sandbox.impl.Checker$4.call(Checker.java:207) at org.kohsuke.groovy.sandbox.GroovyInterceptor.onSuperCall(GroovyInterceptor.java:49) at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onSuperCall(SandboxInterceptor.java:380) at org.kohsuke.groovy.sandbox.impl.Checker$4.call(Checker.java:204) at org.kohsuke.groovy.sandbox.impl.Checker.checkedSuperCall(Checker.java:210) at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.superCall(SandboxInvoker.java:24) at B.testWithoutArgs(WorkflowScript:20) at WorkflowScript.run(WorkflowScript:35) 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.fixName(FunctionCallBlock.java:77) at sun.reflect.GeneratedMethodAccessor190.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.ConstantBlock.eval(ConstantBlock.java:21) at com.cloudbees.groovy.cps.Next.step(Next.java:83) at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:173) at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:162) at org.codehaus.groovy.runtime.GroovyCategorySupport$ThreadCategoryInfo.use(GroovyCategorySupport.java:122) at org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:261) at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:162) at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$001(SandboxContinuable.java:19) at org.jenkinsci.plugins.workflow.cps.SandboxContinuable$1.call(SandboxContinuable.java:35) at org.jenkinsci.plugins.workflow.cps.SandboxContinuable$1.call(SandboxContinuable.java:32) at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovySandbox.runInSandbox(GroovySandbox.java:108) at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:32) at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:174) at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:330) at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$100(CpsThreadGroup.java:82) at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:242) at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:230) 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:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748) Finished: FAILURE
- is related to
-
JENKINS-42563 Calling super.method(...) in shared library fails with CpsCallableInvocation
- Resolved
- relates to
-
JENKINS-45904 toString method in shared library class not correctly resolved
- Resolved
- links to