Skip to content

Commit

Permalink
Diagnosing another symptom of jenkinsci/groovy-sandbox#7.
Browse files Browse the repository at this point in the history
  • Loading branch information
jglick committed Jun 30, 2016
1 parent 37274a8 commit 0a40fc0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/main/java/org/jenkinsci/plugins/workflow/cps/DSL.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public Object invokeMethod(String name, Object args) {
}
final StepDescriptor d = functions.get(name);
if (d == null) {
// TODO probably this should be throwing a subtype of groovy.lang.MissingMethodException
throw new NoSuchMethodError("No such DSL method '" + name + "' found among " + functions.keySet());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,25 +128,27 @@ public void pauseInsideLoad() throws Exception {
WorkflowJob p = jenkins.createProject(WorkflowJob.class, "p");
jenkins.getWorkspaceFor(p).child("a.groovy").write("def call(arg) {echo \"a ran on ${arg}\"}; this", null);
ScriptApproval.get().approveSignature("method groovy.lang.Binding getVariables");
// TODO does not work (fails in first build below) if you invoke as a(…) rather than a.call(…) without setting sandbox=false; get NoSuchMethodError: No such DSL method 'a' found among […]
jenkins.getWorkspaceFor(p).child("b.groovy").write("def m(arg) {echo \"binding=${binding.variables}\"; a.call(\"${arg} from b\")}; this", null);
jenkins.getWorkspaceFor(p).child("b.groovy").write("def m(arg) {echo \"binding=${binding.variables}\"; a(\"${arg} from b\")}; this", null);
// Control case:
p.setDefinition(new CpsFlowDefinition("a = 0; def b; node {a = load 'a.groovy'; b = load 'b.groovy'}; echo \"binding=${binding.variables}\"; b.m('value')", true));
// TODO if you enable sandbox here, build fails: NoSuchMethodError: No such DSL method 'a' found among […]
// SandboxInterceptor.onMethodCall is given Script2 as the receiver and "a" as the method, when really it should be asked about onGetProperty(Script2.a) followed by onMethodCall(Script1.call).
// Works fine if you use a.call(…) rather than a(…).
p.setDefinition(new CpsFlowDefinition("a = 0; def b; node {a = load 'a.groovy'; b = load 'b.groovy'}; echo \"binding=${binding.variables}\"; b.m('value')", false));
story.j.assertLogContains("a ran on value from b", story.j.assertBuildStatusSuccess(p.scheduleBuild2(0)));
// Test case:
p.setDefinition(new CpsFlowDefinition("a = 0; def b; node {a = load 'a.groovy'; b = load 'b.groovy'}; semaphore 'wait'; echo \"binding=${binding.variables}\"; b.m('value')", true));
p.setDefinition(new CpsFlowDefinition("a = 0; def b; node {a = load 'a.groovy'; b = load 'b.groovy'}; semaphore 'wait'; echo \"binding=${binding.variables}\"; b.m('value')", /* TODO ditto */false));
WorkflowRun b = p.scheduleBuild2(0).getStartCondition().get();
SemaphoreStep.waitForStart("wait/1", b);
}
});
story.addStep(new Statement() {
@Override public void evaluate() throws Throwable {
WorkflowJob p = jenkins.getItemByFullName("p", WorkflowJob.class);
WorkflowRun b = p.getBuildByNumber(1);
WorkflowRun b = p.getBuildByNumber(2);
SemaphoreStep.success("wait/1", null);
story.j.assertLogContains("a ran on value from b", story.j.waitForCompletion(b));
story.j.assertLogContains("a ran on value from b", story.j.assertBuildStatusSuccess(story.j.waitForCompletion(b)));
// Better case:
jenkins.getWorkspaceFor(p).child("b.groovy").write("def m(a, arg) {a.call(\"${arg} from b\")}; this", null);
jenkins.getWorkspaceFor(p).child("b.groovy").write("def m(a, arg) {a(\"${arg} from b\")}; this", null);
p.setDefinition(new CpsFlowDefinition("def a; def b; node {a = load 'a.groovy'; b = load 'b.groovy'}; b.m(a, 'value')", true));
story.j.assertLogContains("a ran on value from b", story.j.assertBuildStatusSuccess(p.scheduleBuild2(0)));
}
Expand Down

0 comments on commit 0a40fc0

Please sign in to comment.