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; }
/** * 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; } }; }
context.getListener().getLogger().println("Error evaluating token: " + e.getMessage()); } catch (Exception e) { Logger.getLogger(ContentBuilder.class.getName()).log(Level.SEVERE, null, e);
expandedTargetLocation = TokenMacro.expandAll(build, workspace, listener, configFile.getTargetLocation()); } catch (MacroEvaluationException e) { listener.getLogger().println("[ERROR] failed to expand variables in target location '" + configFile.getTargetLocation() + "' : " + e.getMessage()); expandedTargetLocation = configFile.getTargetLocation(); listener.getLogger().println("[ERROR] failed to expand variables in content of " + config.name + " - " + e.getMessage());
expandedTargetLocation = TokenMacro.expandAll(build, ws, listener, expandedTargetLocation); } catch (MacroEvaluationException e) { listener.getLogger().println("[ERROR] failed to expand variables in target location '" + expandedTargetLocation + "' : " + e.getMessage());