public String r( String value ) throws MacroEvaluationException, IOException, InterruptedException { return strip( TokenMacro.expandAll(build, workspace, listener, value ) ); } }
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(); }
String labelExpanded = nodeLabel; try { labelExpanded = TokenMacro.expandAll(build, listener, labelExpanded); } catch (MacroEvaluationException e) { labelExpanded = nodeLabel;
/** * Expands all env vars. In case of AbstractBuild also expands token macro and build vars * * @param run build context * @param listener usually used to log something to console while building env vars * * @return string with expanded vars and tokens */ public String expandAll(Run<?, ?> run, TaskListener listener) throws IOException, InterruptedException { if (run instanceof AbstractBuild) { try { return TokenMacro.expandAll( (AbstractBuild) run, listener, content, false, Collections.<TokenMacro>emptyList() ); } catch (MacroEvaluationException e) { LOGGER.error("Can't process token content {} in {} ({})", content, run.getParent().getFullName(), e.getMessage()); LOGGER.trace(e.getMessage(), e); return content; } } else { // fallback to env vars only because of token-macro allow only AbstractBuild in 1.11 return run.getEnvironment(listener).expand(trimToEmpty(content)); } }
@Override public Environment setUp(AbstractBuild build, Launcher launcher, BuildListener listener) throws IOException, InterruptedException { try { String version = TokenMacro.expandAll(build, listener, getVersionTemplate()); setVersion(build, version); listener.getLogger().println("Creating version: " + version); if (isUpdateDisplayName()) { build.setDisplayName(version); } } catch (MacroEvaluationException e) { listener.getLogger().println("Error creating version: " + e.getMessage()); LOG.log(Level.WARNING, "Error creating version", e); } return new Environment() { @Override public boolean tearDown(AbstractBuild build, BuildListener listener) throws IOException, InterruptedException { return true; } }; }
macros.addAll(additionalMacros); if(context.getRun() != null) { newText = TokenMacro.expandAll(context.getRun(), context.getWorkspace(), context.getListener(), newText, false, macros); } else { context.getListener().getLogger().println("Job type does not allow token replacement.");