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 String evaluate(AbstractBuild<?, ?> context, TaskListener listener, String macroName) throws MacroEvaluationException, IOException, InterruptedException { String version = PipelineVersionContributor.getVersion(context); if (version == null) { throw new MacroEvaluationException("Could not find " + PipelineVersionContributor.VERSION_PARAMETER + " parameter on this build!"); } return version; }
@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; }
/** * 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)); } }
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 String evaluate(AbstractBuild<?, ?> context, TaskListener listener, String macroName) throws MacroEvaluationException, IOException, InterruptedException { final Script script = ScriptHelper.getScript(scriptId, true); if (script == null) { throw new MacroEvaluationException(Messages.tokenmacro_ScriptDoesNotExist(scriptId)); } else if (!script.nonAdministerUsing) { listener.getLogger().println(Messages.tokenmacro_AdminScriptOnly(scriptId)); throw new MacroEvaluationException(Messages.tokenmacro_AdminScriptOnly(scriptId)); } VirtualChannel channel; if (script.onlyMaster) { channel = MasterComputer.localChannel; } else { channel = context.getWorkspace().getChannel(); } Object output = channel.call(new GroovyScript(script.script, null, true, listener, null, context)); return output != null ? output.toString() : ""; }
@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; } }; }
} catch (MacroEvaluationException e) { logger.println("Unable to expand commit SHA value"); e.printStackTrace(logger); return Arrays.asList();
context.getListener().getLogger().println("Error evaluating token: " + e.getMessage()); } catch (Exception e) { Logger.getLogger(ContentBuilder.class.getName()).log(Level.SEVERE, null, e);
} catch (MacroEvaluationException e) { labelExpanded = nodeLabel; e.printStackTrace(listener.getLogger());
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());
} catch (MacroEvaluationException mee) { logger.println("Cannot expand build key from parameter. Processing with default build key"); mee.printStackTrace(logger); key.append(getDefaultBuildKey(run));
expandedTargetLocation = TokenMacro.expandAll(build, ws, listener, expandedTargetLocation); } catch (MacroEvaluationException e) { listener.getLogger().println("[ERROR] failed to expand variables in target location '" + expandedTargetLocation + "' : " + e.getMessage());