Skip to content
Permalink
Browse files

[JENKINS-26135]

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 fee680c0736ee5a5610ac23158c45c0e273ea951
Showing with 15 additions and 0 deletions.
  1. +15 −0 cps/src/main/java/org/jenkinsci/plugins/workflow/cps/CpsScript.java
@@ -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.*;
@@ -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);
}

0 comments on commit fee680c

Please sign in to comment.
You can’t perform that action at this time.