public String r( String value ) throws MacroEvaluationException, IOException, InterruptedException { return strip( TokenMacro.expandAll(build, workspace, listener, value ) ); } }
public EmailExtScriptTokenMacroWhitelist() { List<TokenMacro> list = new ArrayList<>(); list.addAll(TokenMacro.all()); list.addAll(ContentBuilder.getPrivateMacros()); this.macros = Collections.unmodifiableList(list); }
for(TokenMacro m : TokenMacro.all()) { if(m.acceptsMacroName(name)) { macro = m; break; if(m.acceptsMacroName(name)) { macro = m; break; TaskListener listener = (TaskListener)this.getBinding().getVariable("listener"); return macro.evaluate(build, workspace, listener, name, argsMap, argsMultimap); } else {
@Override public boolean permitsMethod(@Nonnull Method method, @Nonnull Object receiver, @Nonnull Object[] args) { //method groovy.lang.GroovyObject invokeMethod java.lang.String java.lang.Object (SimpleTemplateScript2 BUILD_ID) if (method.getDeclaringClass() == GroovyObject.class && receiver instanceof EmailExtScript && "invokeMethod".equals(method.getName()) && args.length > 0) { EmailExtScript script = (EmailExtScript)receiver; String name = String.valueOf(args[0]); for (TokenMacro m : macros) { if (m.acceptsMacroName(name)) { return true; } } //Else check environment Run<?,?> build = (Run<?,?>)script.getBinding().getVariable("build"); TaskListener listener = (TaskListener)script.getBinding().getVariable("listener"); try { EnvVars vars = build.getEnvironment(listener); return vars.containsKey(name); } catch (IOException | InterruptedException e) { Logger.getLogger(getClass().getName()).log(Level.WARNING, "Failed to expand environment when evaluating " + name + " on " + build.getExternalizableId(), e); } } return false; } }
private String expandAll(String s) throws MacroEvaluationException, IOException, InterruptedException { return TokenMacro.expandAll(build, listener, s); }
private String expand(Run<?, ?> build, String text) { try { if (build instanceof AbstractBuild && !Strings.isNullOrEmpty(text)) { text = TokenMacro.expandAll((AbstractBuild) build, TaskListener.NULL, text); } } catch (Exception e) { e.printStackTrace(); } return text; }
private String getAdditionalTag(AbstractBuild build, TaskListener listener) { // Do a macro expansion on the addJenkinsAction token // Job property String tagToken = additionalTag; // Do any macro expansions try { if (!Strings.isNullOrEmpty(tagToken)) tagToken = TokenMacro.expandAll(build, listener, tagToken); } catch (Exception e) { LOGGER.warn("can't expand macro", e); } return tagToken; }
private List<String> expandTags(hudson.model.Run<?, ?> build, FilePath workspace, Launcher launcher, TaskListener listener) { List<String> eTags = new ArrayList<>(tags.size()); for (String tag : tags) { try { eTags.add(TokenMacro.expandAll(build, workspace, listener, tag)); } catch (MacroEvaluationException | IOException | InterruptedException e) { listener.getLogger().println("Couldn't macro expand tag " + tag); } } return eTags; }
@Override public boolean runPerform(final AbstractBuild<?, ?> build, final BuildListener listener) throws Exception { final String expanded1 = TokenMacro.expandAll(build, listener, arg1); final String expanded2 = TokenMacro.expandAll(build, listener, arg2); listener.getLogger().println(Messages.stringsMatchCondition_console_args(expanded1, expanded2)); if (expanded1 == null) return false; return ignoreCase ? expanded1.equalsIgnoreCase(expanded2) : expanded1.equals(expanded2); }
@Override public boolean runPerform(final AbstractBuild<?, ?> build, final BuildListener listener) throws Exception { final String expandedExpression = TokenMacro.expandAll(build, listener, expression); String expandedLabel = TokenMacro.expandAll(build, listener, label); listener.getLogger().println(Messages.expressionCondition_console_args(expandedExpression, expandedLabel)); return expandedLabel.matches(expandedExpression); }
private static String decode(AbstractBuild<?, ?> build, String template) throws MacroEvaluationException, IOException, InterruptedException { if (build == null) { return hideVariable(template); } else { return TokenMacro.expandAll(build, TaskListener.NULL, template); } }
@Override public boolean runPerform(final AbstractBuild<?, ?> build, final BuildListener listener) throws Exception { final String expandedToken = Util.fixEmptyAndTrim(TokenMacro.expandAll(build, listener, token)); listener.getLogger().println(Messages.booleanCondition_check(expandedToken, RUN_REGEX.pattern(), token)); if (expandedToken == null) { return false; } return RUN_REGEX.matcher(expandedToken.toLowerCase()).matches(); }
private String evaluateMacro(Run<?, ?> build, FilePath workspace, TaskListener listener, String value) throws InterruptedException, IOException { try { return TokenMacro.expandAll(build, workspace, listener, value); } catch (MacroEvaluationException e) { log(listener, String.format("Could not evaluate macro '%s': %s", value, e.getMessage())); } return value; }
@Override public boolean runPerform(final AbstractBuild<?, ?> build, final BuildListener listener) throws Exception { final String leftString = TokenMacro.expandAll(build, listener, lhs); final double left = Double.parseDouble(leftString); final String rightString = TokenMacro.expandAll(build, listener, rhs); final double right = Double.parseDouble(rightString); listener.getLogger().println(Messages.numericalComparison_console_args(left, comparator.getDescriptor().getDisplayName(), right)); return comparator.isTrue(left, right); }
private String expandStashURL(Run<?, ?> run, final TaskListener listener) { String url = stashServerBaseUrl; DescriptorImpl descriptor = getDescriptor(); if (url == null || url.isEmpty()) { url = descriptor.getStashRootUrl(); } try { if (!(run instanceof AbstractBuild<?, ?>)) { url = TokenMacro.expandAll(run, new FilePath(run.getRootDir()), listener, url); } else { url = TokenMacro.expandAll((AbstractBuild<?, ?>) run, listener, url); } } catch (IOException | InterruptedException | MacroEvaluationException ex) { PrintStream logger = listener.getLogger(); logger.println("Unable to expand Stash Server URL"); ex.printStackTrace(logger); } return url; }
@Override public List<AbstractBuildParameters> getParameters(AbstractBuild<?, ?> build, TaskListener listener) throws IOException, InterruptedException, AbstractBuildParameters.DontTriggerException { String nodeListStringExpanded = nodeListString; try { nodeListStringExpanded = TokenMacro.expandAll(build, listener, nodeListStringExpanded); } catch (MacroEvaluationException e) { nodeListStringExpanded = nodeListString; e.printStackTrace(listener.getLogger()); } List<AbstractBuildParameters> params = Lists.newArrayList(); if (StringUtils.isBlank(nodeListStringExpanded)) { listener.getLogger().println("[WARN] no node name was given! [" + nodeListString + "], can't trigger other project"); } else { String nodes[] = nodeListStringExpanded.trim().split(","); if (nodes == null || nodes.length == 0) { params.add(new NodeLabelBuildParameter(name, nodeListStringExpanded)); } else { for (int i = 0; i < nodes.length; i++) { params.add(new NodeLabelBuildParameter(name, nodes[i])); } } } return params; }
public Action getAction(AbstractBuild<?, ?> build, TaskListener listener) throws IOException, InterruptedException { String labelExpanded = nodeLabel; try { labelExpanded = TokenMacro.expandAll(build, listener, labelExpanded); } catch (MacroEvaluationException e) { labelExpanded = nodeLabel; e.printStackTrace(listener.getLogger()); } LabelParameterValue parameterValue = new LabelParameterValue(name, labelExpanded, false, new AllNodeEligibility()); listener.getLogger().println("define: " + parameterValue); return new ParametersAction(parameterValue); }
@Override public void perform(hudson.model.Run<?, ?> run, FilePath workspace, Launcher launcher, TaskListener listener) throws InterruptedException, IOException { List<String> expandedTags; expandedTags = expandTags(run, workspace, launcher, listener); String expandedDockerFileDirectory = dockerFileDirectory; try { expandedDockerFileDirectory = TokenMacro.expandAll(run, workspace, listener, this.dockerFileDirectory); } catch (MacroEvaluationException e) { listener.getLogger().println("Couldn't macro expand docker file directory " + dockerFileDirectory); } new Run(run, launcher, listener, new FilePath(workspace, expandedDockerFileDirectory), expandedTags, getCloud(launcher)).run(); }
@Override public boolean runPerform(final AbstractBuild<?, ?> build, final BuildListener listener) throws Exception { final String expandedFile = TokenMacro.expandAll(build, listener, file); listener.getLogger().println(Messages.fileExistsCondition_check(expandedFile)); return baseDir.getBaseDirectory(build).child(expandedFile).exists(); }