Failed to load and run groovy script in a pipeline job

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Failed to load and run groovy script in a pipeline job

Owen Liu


I want to load a groovy script and execute methods of that script in a simple scripted pipeline. but it failed to run the groovy script when loading the groovy script, the script is very simple, I tested it on my local computer, it ran successfully, I have the following configuration:

checkout([$class: 'GitSCM', branches: [[name: "refs/heads/master"]],
doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [],
userRemoteConfigs: [[credentialsId: 'xxx', url:

def script=load "${env.WORKSPACE}/scripts/debug1.groovy"

def initVariableBindings() {
def tempArr=["WORKSPACE"]
tempArr.each {
if (System.getenv(it) != null) {
this.binding.setProperty(it, System.getenv(it))
} else if (System.getProperty(it) != null) {
this.binding.setProperty(it, System.getProperty(it))
} else {
println "Failed to init variable "+ it;
def hello(){
println "hello ${WORKSPACE}"

it throws the following exception:

groovy.lang.MissingFieldException: No such field: binding for class: Script1 at groovy.lang.MetaClassImpl.getAttribute( at groovy.lang.MetaClassImpl.getAttribute( at org.codehaus.groovy.runtime.InvokerHelper.getAttribute( at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.getField( at org.kohsuke.groovy.sandbox.impl.Checker$ at org.kohsuke.groovy.sandbox.GroovyInterceptor.onGetAttribute( at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onGetAttribute( at org.kohsuke.groovy.sandbox.impl.Checker$ at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetAttribute( at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.getAttribute( at com.cloudbees.groovy.cps.impl.AttributeAccessBlock.rawGet( at Script1.initVariableBindings(Script1.groovy:8) at com.cloudbees.groovy.cps.CpsDefaultGroovyMethods.each(CpsDefaultGroovyMethods:2030) at com.cloudbees.groovy.cps.CpsDefaultGroovyMethods.each(CpsDefaultGroovyMethods:2015) at com.cloudbees.groovy.cps.CpsDefaultGroovyMethods.each(CpsDefaultGroovyMethods:2056) at Script1.initVariableBindings(Script1.groovy:4) at at ___cps.transform___(Native Method)

it complains that the List variable tempArr in the function initVariableBindings is not a binding property, but it is a local variable, it should work, is this normal behavior and why or a bug of groovy plugin?


You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit