private CpsScript parseScript() throws IOException { // classloader hierarchy. See doc/classloader.md trusted = new CpsGroovyShellFactory(this).forTrusted().build(); shell = new CpsGroovyShellFactory(this).withParent(trusted).build(); CpsScript s = (CpsScript) shell.reparse("WorkflowScript",script); for (Entry<String, String> e : loadedScripts.entrySet()) { shell.reparse(e.getKey(), e.getValue()); } s.execution = this; if (false) { System.out.println("scriptName="+s.getClass().getName()); System.out.println(Arrays.asList(s.getClass().getInterfaces())); System.out.println(Arrays.asList(s.getClass().getDeclaredFields())); System.out.println(Arrays.asList(s.getClass().getDeclaredMethods())); } return s; }
@RequirePOST public JSON doCheckScriptCompile(@AncestorInPath Item job, @QueryParameter String value) { if (!job.hasPermission(Job.CONFIGURE)) { return CpsFlowDefinitionValidator.CheckStatus.SUCCESS.asJSON(); } try { CpsGroovyShell trusted = new CpsGroovyShellFactory(null).forTrusted().build(); new CpsGroovyShellFactory(null).withParent(trusted).withSandbox(true).build().getClassLoader().parseClass(value); } catch (CompilationFailedException x) { return JSONArray.fromObject(CpsFlowDefinitionValidator.toCheckStatus(x).toArray()); } return CpsFlowDefinitionValidator.CheckStatus.SUCCESS.asJSON(); // Approval requirements are managed by regular stapler form validation (via doCheckScript) }