[JIRA] (JENKINS-42779) groovy.lang.MissingFieldException: No such field: binding for class: WorkflowScript

218 views
Skip to first unread message

sorin.sbarnea@gmail.com (JIRA)

unread,
Mar 14, 2017, 7:16:02 PM3/14/17
to jenkinsc...@googlegroups.com
Sorin Sbarnea created an issue
 
Jenkins / Improvement JENKINS-42779
groovy.lang.MissingFieldException: No such field: binding for class: WorkflowScript
Issue Type: Improvement Improvement
Assignee: Unassigned
Components: pipeline
Created: 2017/Mar/14 11:15 PM
Priority: Critical Critical
Reporter: Sorin Sbarnea

I tried to print all pipeline variables in a loop and I got an exception from groovy.

// put this inside stage block:

for (k in this.binding.variables) {
  try {
    v = this.binding.variables[k]
    println "$k = $v";
    }
  catch(Exception ex) {
    println("Catching the exception: ${ex}");
    }	
}
groovy.lang.MissingFieldException: No such field: binding for class: WorkflowScript
	at groovy.lang.MetaClassImpl.getAttribute(MetaClassImpl.java:2823)
	at groovy.lang.MetaClassImpl.getAttribute(MetaClassImpl.java:3759)
	at org.codehaus.groovy.runtime.InvokerHelper.getAttribute(InvokerHelper.java:145)
	at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.getField(ScriptBytecodeAdapter.java:306)
	at org.kohsuke.groovy.sandbox.impl.Checker$6.call(Checker.java:325)
	at org.kohsuke.groovy.sandbox.GroovyInterceptor.onGetAttribute(GroovyInterceptor.java:80)
	at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onGetAttribute(SandboxInterceptor.java:380)
	at org.kohsuke.groovy.sandbox.impl.Checker$6.call(Checker.java:322)
	at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetAttribute(Checker.java:319)
	at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.getAttribute(SandboxInvoker.java:36)
	at com.cloudbees.groovy.cps.impl.AttributeAccessBlock.rawGet(AttributeAccessBlock.java:20)
	at WorkflowScript.run(WorkflowScript:41)
	at ___cps.transform___(Native Method)
	at com.cloudbees.groovy.cps.impl.PropertyishBlock$ContinuationImpl.get(PropertyishBlock.java:74)
	at com.cloudbees.groovy.cps.LValueBlock$GetAdapter.receive(LValueBlock.java:30)
	at com.cloudbees.groovy.cps.impl.PropertyishBlock$ContinuationImpl.fixName(PropertyishBlock.java:66)
	at sun.reflect.GeneratedMethodAccessor198.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: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)
Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v7.3.0#73011-sha1:3c73d0e)
Atlassian logo

andrew.bayer@gmail.com (JIRA)

unread,
Mar 28, 2017, 6:40:02 PM3/28/17
to jenkinsc...@googlegroups.com
Andrew Bayer commented on Improvement JENKINS-42779
 
Re: groovy.lang.MissingFieldException: No such field: binding for class: WorkflowScript

I'll defer to Kohsuke Kawaguchi or Jesse Glick, but I don't think binding is supposed to be available at the user level here.

andrew.bayer@gmail.com (JIRA)

unread,
Feb 26, 2018, 5:02:03 PM2/26/18
to jenkinsc...@googlegroups.com

So fwiw, I reproduced this with the original without being in a stage. And it works if you go with this.getBinding() instead of this.binding. Why that is...I'm still not exactly sure. So I'm going to leave this open to remind me to dig into that at some point, but it's not exactly a priority.

andrew.bayer@gmail.com (JIRA)

unread,
Feb 26, 2018, 5:02:04 PM2/26/18
to jenkinsc...@googlegroups.com

andrew.bayer@gmail.com (JIRA)

unread,
Feb 26, 2018, 5:02:04 PM2/26/18
to jenkinsc...@googlegroups.com

andrew.bayer@gmail.com (JIRA)

unread,
Feb 26, 2018, 5:02:05 PM2/26/18
to jenkinsc...@googlegroups.com

aburdajewicz@cloudbees.com (JIRA)

unread,
Sep 22, 2019, 11:13:04 PM9/22/19
to jenkinsc...@googlegroups.com
Allan BURDAJEWICZ commented on Bug JENKINS-42779
 
Re: groovy.lang.MissingFieldException: No such field: binding for class: WorkflowScript

I have noticed that getBinding() only returns the variable steps that point to the DSL. Looking at https://github.com/jenkinsci/workflow-cps-plugin/blob/workflow-cps-2.67/src/main/java/org/jenkinsci/plugins/workflow/cps/DSL.java#L131-L200, you could get all sort of things from that object (would need approve a lot of signatures through Script security though...):

println "\nfunctions\n***********"
println this.steps.functions.collect { k,v -> v.getFunctionName()}

println "\nstepClassNames\n***********"
println this.steps.stepClassNames.collect { k,v -> v.getFunctionName()}

println "\nunreportedAmbiguousFunctions\n***********"
println this.steps.unreportedAmbiguousFunctions.collect { k,v -> v.getFunctionName() }

println "\nallGlobalVariables\n***********"
println org.jenkinsci.plugins.workflow.cps.GlobalVariable.forRun(currentBuild.rawBuild).collect { var -> var.getName() }

println "\nallSymbols\n***********"
println getAllSymbols().collectMany { symbol -> org.jenkinsci.plugins.structs.SymbolLookup.getSymbolValue(symbol) }

@NonCPS
def getAllSymbols() {
    return org.jvnet.hudson.annotation_indexer.Index.list(
            org.jenkinsci.Symbol.class,
            jenkins.model.Jenkins.get().pluginManager.uberClassLoader,
            Class.class)
}
This message was sent by Atlassian Jira (v7.13.6#713006-sha1:cc4451f)
Atlassian logo
Reply all
Reply to author
Forward
0 new messages