use of hudson.model.ParameterValue in project hudson-2.x by hudson.
the class BuildCommand method run.
protected int run() throws Exception {
job.checkPermission(Item.BUILD);
ParametersAction a = null;
if (!parameters.isEmpty()) {
ParametersDefinitionProperty pdp = job.getProperty(ParametersDefinitionProperty.class);
if (pdp == null)
throw new AbortException(job.getFullDisplayName() + " is not parameterized but the -p option was specified");
List<ParameterValue> values = new ArrayList<ParameterValue>();
for (Entry<String, String> e : parameters.entrySet()) {
String name = e.getKey();
ParameterDefinition pd = pdp.getParameterDefinition(name);
if (pd == null)
throw new AbortException(String.format("\'%s\' is not a valid parameter. Did you mean %s?", name, EditDistance.findNearest(name, pdp.getParameterDefinitionNames())));
values.add(pd.createValue(this, e.getValue()));
}
for (ParameterDefinition pd : pdp.getParameterDefinitions()) {
if (parameters.get(pd.getName()) == null) {
values.add(pd.getDefaultParameterValue());
}
}
a = new ParametersAction(values);
}
Future<? extends AbstractBuild> f = job.scheduleBuild2(0, new CLICause(), a);
if (!sync)
return 0;
// wait for the completion
AbstractBuild b = f.get();
stdout.println("Completed " + b.getFullDisplayName() + " : " + b.getResult());
return b.getResult().ordinal;
}
use of hudson.model.ParameterValue in project blueocean-plugin by jenkinsci.
the class PipelineStepImpl method parseValue.
private Object parseValue(InputStepExecution execution, JSONArray parameters, StaplerRequest request) throws IOException, InterruptedException {
Map<String, Object> mapResult = new HashMap<>();
InputStep input = execution.getInput();
for (Object o : parameters) {
JSONObject p = (JSONObject) o;
String name = (String) p.get(NAME_ELEMENT);
if (name == null) {
throw new ServiceException.BadRequestException("name is required parameter element");
}
ParameterDefinition d = null;
for (ParameterDefinition def : input.getParameters()) {
if (def.getName().equals(name))
d = def;
}
if (d == null)
throw new ServiceException.BadRequestException("No such parameter definition: " + name);
ParameterValue v = d.createValue(request, p);
if (v == null) {
continue;
}
mapResult.put(name, convert(name, v));
}
// If a destination value is specified, push the submitter to it.
String valueName = input.getSubmitterParameter();
if (valueName != null && !valueName.isEmpty()) {
Authentication a = Jenkins.getAuthentication2();
mapResult.put(valueName, a.getName());
}
switch(mapResult.size()) {
case 0:
// no value if there's no parameter
return null;
case 1:
return mapResult.values().iterator().next();
default:
return mapResult;
}
}
use of hudson.model.ParameterValue in project blueocean-plugin by jenkinsci.
the class RunContainerImpl method create.
/**
* Schedules a build. If build already exists in the queue and the pipeline does not
* support running multiple builds at the same time, return a reference to the existing
* build.
*
* @return Queue item.
*/
@Override
public BlueRun create(StaplerRequest request) {
job.checkPermission(Item.BUILD);
if (job instanceof Queue.Task) {
ScheduleResult scheduleResult;
List<ParameterValue> parameterValues = getParameterValue(request);
int expectedBuildNumber = job.getNextBuildNumber();
if (parameterValues.size() > 0) {
scheduleResult = Jenkins.get().getQueue().schedule2((Queue.Task) job, 0, new ParametersAction(parameterValues), new CauseAction(new Cause.UserIdCause()));
} else {
scheduleResult = Jenkins.get().getQueue().schedule2((Queue.Task) job, 0, new CauseAction(new Cause.UserIdCause()));
}
// Keep FB happy.
// scheduleResult.getItem() will always return non-null if scheduleResult.isAccepted() is true
final Queue.Item item = scheduleResult.getItem();
if (scheduleResult.isAccepted() && item != null) {
return new QueueItemImpl(pipeline.getOrganization(), item, pipeline, expectedBuildNumber, pipeline.getLink().rel("queue").rel(Long.toString(item.getId())), pipeline.getLink()).toRun();
} else {
throw new ServiceException.UnexpectedErrorException("Queue item request was not accepted");
}
} else {
throw new ServiceException.NotImplementedException("This pipeline type does not support being queued.");
}
}
use of hudson.model.ParameterValue in project workflow-cps-plugin by jenkinsci.
the class ParamsVariable method getValue.
@SuppressWarnings("unchecked")
@Override
public Object getValue(CpsScript script) throws Exception {
Run<?, ?> b = script.$build();
if (b == null) {
throw new IllegalStateException("cannot find owning build");
}
// Could extend AbstractMap and make a Serializable lazy wrapper, but getValue impls seem cheap anyway.
Map<String, Object> values = new HashMap<>();
ParametersAction action = b.getAction(ParametersAction.class);
if (action != null) {
List<ParameterValue> parameterValues;
try {
// TODO 1.651.2+ remove reflection
parameterValues = (List<ParameterValue>) ParametersAction.class.getMethod("getAllParameters").invoke(action);
} catch (NoSuchMethodException x) {
parameterValues = action.getParameters();
}
for (ParameterValue parameterValue : parameterValues) {
addValue(values, parameterValue);
}
}
ParametersDefinitionProperty prop = b.getParent().getProperty(ParametersDefinitionProperty.class);
if (prop != null) {
// JENKINS-35698: look for default values as well
for (ParameterDefinition param : prop.getParameterDefinitions()) {
if (!values.containsKey(param.getName())) {
ParameterValue defaultParameterValue = param.getDefaultParameterValue();
if (defaultParameterValue != null) {
addValue(values, defaultParameterValue);
}
}
}
}
return Collections.unmodifiableMap(values);
}
use of hudson.model.ParameterValue in project selenium_java by sergueik.
the class BuildDetailsResolver method addParametersFromContext.
private static void addParametersFromContext(BuildDetailsImpl details, Run<?, ?> run) throws IOException, InterruptedException {
LOGGER.finest("resolving build parameters");
List<BuildParameter> buildParameters = new ArrayList<BuildParameter>();
for (Action action : run.getAllActions()) {
if (!ParametersAction.class.isInstance(action)) {
continue;
}
ParametersAction paramAction = (ParametersAction) action;
for (ParameterValue param : paramAction.getParameters()) {
LOGGER.finest("found parameter: " + param);
String paramId = run.getId() + "-" + param.getName();
buildParameters.add(new BuildParameterImpl(paramId, param.getName(), param.getValue().toString(), details));
}
}
details.setParameters(buildParameters);
}
Aggregations