Skip to content

Commit

Permalink
[JENKINS-26135]
Browse files Browse the repository at this point in the history
Global variable should be usable as a function, just like in Groovy
Closure property can be called like a function.

Originally-Committed-As: 9cdadd25a63ea5f586f275741cd077f9ab2e7682
  • Loading branch information
kohsuke committed May 22, 2015
1 parent 0c8bbb1 commit fee680c
Showing 1 changed file with 15 additions and 0 deletions.
Expand Up @@ -38,6 +38,7 @@
import org.codehaus.groovy.control.CompilationFailedException;
import org.codehaus.groovy.runtime.DefaultGroovyMethods;
import org.codehaus.groovy.runtime.DefaultGroovyStaticMethods;
import org.codehaus.groovy.runtime.InvokerHelper;
import org.codehaus.groovy.runtime.InvokerInvocationException;
import org.jenkinsci.plugins.workflow.cps.persistence.PersistIn;
import static org.jenkinsci.plugins.workflow.cps.persistence.PersistenceContext.*;
Expand Down Expand Up @@ -94,6 +95,20 @@ public CpsScript() throws IOException {
*/
@Override
public final Object invokeMethod(String name, Object args) {
// if global variables are defined by that name, try to call it.
// the 'call' convention comes from Closure
for (GlobalVariable v : GlobalVariable.ALL) {
if (v.getName().equals(name)) {
try {
Object o = v.getValue(this);
return InvokerHelper.getMetaClass(o).invokeMethod(o,"call",args);
} catch (Exception x) {
throw new InvokerInvocationException(x);
}
}
}

// otherwise try Step impls.
DSL dsl = (DSL) getBinding().getVariable(STEPS_VAR);
return dsl.invokeMethod(name,args);
}
Expand Down

0 comments on commit fee680c

Please sign in to comment.