@Deprecated public AbstractScriptTrigger(List<RecipientProvider> recipientProviders, String recipientList, String replyTo, String subject, String body, String attachmentsPattern, int attachBuildLog, String contentType, String triggerScript) { this(recipientProviders, recipientList, replyTo, subject, body, attachmentsPattern, attachBuildLog, contentType, new SecureGroovyScript(triggerScript, false, null)); }
@Override public EmailTrigger createDefault() { return new PreBuildScriptTrigger(defaultRecipientProviders, "", "$PROJECT_DEFAULT_REPLYTO", "$PROJECT_DEFAULT_SUBJECT", "$PROJECT_DEFAULT_CONTENT", "", 0, "project", new SecureGroovyScript("", false, null)); } }
@Override public EmailTrigger createDefault() { return new ScriptTrigger(defaultRecipientProviders, "", "$PROJECT_DEFAULT_REPLYTO", "$PROJECT_DEFAULT_SUBJECT", "$PROJECT_DEFAULT_CONTENT", "", 0, "project", new SecureGroovyScript("", false, null)); } }
@SuppressWarnings("deprecation") private Object readResolve() { if (secureGroovyScript == null && !StringUtils.isBlank(groovyScriptContent)) { secureGroovyScript = new SecureGroovyScript(groovyScriptContent, false, null).configuring(ApprovalContext.create()); groovyScriptContent = null; } return this; }
@Deprecated public SystemGroovy(final ScriptSource scriptSource, final String bindings, final String classpath) { if (scriptSource instanceof StringScriptSource) { source = new StringSystemScriptSource(new SecureGroovyScript(((StringScriptSource) scriptSource).getCommand(), false, null)); } else { source = new FileSystemScriptSource(((FileScriptSource) scriptSource).getScriptFile()); } this.bindings = bindings; if (Util.fixEmpty(classpath) != null) { throw new UnsupportedOperationException("classpath no longer supported"); // TODO convert StringScriptSource at least } }
/** * Called when object has been deserialized from a stream. * * @return {@code this}, or a replacement for {@code this}. * @throws ObjectStreamException if the object cannot be restored. * @see <a href="http://download.oracle.com/javase/1.3/docs/guide/serialization/spec/input.doc6.html">The Java Object Serialization Specification</a> */ private Object readResolve() throws ObjectStreamException { if (triggerScript != null && secureTriggerScript == null) { this.secureTriggerScript = new SecureGroovyScript(triggerScript, false, null); this.secureTriggerScript.configuring(ApprovalContext.create()); triggerScript = null; } return this; } }
@Override public String evaluate(final AbstractBuild<?, ?> context, final TaskListener listener, final String macroName) throws MacroEvaluationException, IOException, InterruptedException { Jenkins jenkins = Jenkins.getInstance(); if (jenkins == null ) { throw new IllegalStateException("Jenkins instance is null - Jenkins is shutting down?"); } Groovy.DescriptorImpl decs = (Groovy.DescriptorImpl) jenkins.getDescriptorOrDie(Groovy.class); if (decs.getAllowMacro()) { SystemGroovy systemGroovy = new SystemGroovy(new StringSystemScriptSource(new SecureGroovyScript(script, true, null))); Object output = systemGroovy.run(context, (BuildListener) listener, null); return output != null ? output.toString() : ""; } else { return script; } }
SecureGroovyScript script = new SecureGroovyScript(scriptContent, false, null); return executeGroovyScript(logger, script, envVars);
public GroovyScriptExecutor(Script script, List<String> arguments, AbstractBuild<?, ?> build, Logger log) { this.arguments = new ArrayList<>(arguments); this.build = build; this.log = log; String enrichedScript = Util.replaceMacro(script.getContent(), EnvVars.masterEnvVars); secureGroovyScript = new SecureGroovyScript(enrichedScript, script.isSandboxed(), null); secureGroovyScript.configuringWithNonKeyItem(); }
StringUtils.isNotBlank(groovyScriptContent) ? new SecureGroovyScript(groovyScriptContent, false, null).configuring(ApprovalContext.create()) : null);
@SuppressWarnings("deprecation") private Object readResolve() throws Exception { if (command != null) { source = new StringSystemScriptSource(new SecureGroovyScript(command, false, null).configuring(ApprovalContext.create())); command = null; } else if (scriptSource instanceof StringScriptSource) { List<ClasspathEntry> classpathEntries = new ArrayList<ClasspathEntry>(); if (classpath != null) { StringTokenizer tokens = new StringTokenizer(classpath); while (tokens.hasMoreTokens()) { ClasspathEntry ce = new ClasspathEntry(tokens.nextToken()); if (ce.isClassDirectory()) { throw new UnsupportedOperationException("directory-based classpath entries not supported in system Groovy script string source"); } classpathEntries.add(ce); } } source = new StringSystemScriptSource(new SecureGroovyScript(Util.fixNull(((StringScriptSource) scriptSource).getCommand()), false, classpathEntries).configuring(ApprovalContext.create())); scriptSource = null; } else if (scriptSource instanceof FileScriptSource) { if (Util.fixEmpty(classpath) != null) { throw new UnsupportedOperationException("classpath no longer supported in conjunction with system Groovy script file source"); } else { source = new FileSystemScriptSource(((FileScriptSource) scriptSource).getScriptFile()); scriptSource = null; } } return this; }
@Override public SecureGroovyScript getSecureGroovyScript(FilePath projectWorkspace, AbstractBuild<?, ?> build, TaskListener listener) throws IOException, InterruptedException { EnvVars env = build.getEnvironment(listener); String expandedScriptFile = env.expand(this.scriptFile); String text = new FilePath(projectWorkspace, expandedScriptFile).readToString(); return new SecureGroovyScript(text, true, null).configuring(ApprovalContext.create()/* unused but just in case: */.withItem(build.getParent())); }