use of hudson.model.ParameterDefinition 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.ParameterDefinition 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<String, Object>();
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.BadRequestExpception("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.BadRequestExpception("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.getAuthentication();
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.ParameterDefinition in project promoted-builds-plugin by jenkinsci.
the class Status method doBuild.
/**
* Schedules a new build.
* @param req Request
* @param rsp Response
* @throws IOException Functional error
* @throws ServletException Request handling error
*/
public void doBuild(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {
final PromotionProcess process = getProcess();
if (process == null) {
throw new AbortException("Cannot retrieve the promotion process");
}
AbstractBuild<?, ?> target = getTarget();
if (target == null) {
throw new AbortException("Cannot get the target build to be promoted");
}
ManualCondition manualCondition = (ManualCondition) process.getPromotionCondition(ManualCondition.class.getName());
if (!target.hasPermission(Promotion.PROMOTE)) {
if (manualCondition == null || (!manualCondition.getUsersAsSet().isEmpty() && !manualCondition.isInUsersList() && !manualCondition.isInGroupList()))
return;
}
JSONObject formData = req.getSubmittedForm();
List<ParameterValue> paramValues = null;
if (formData != null) {
paramValues = new ArrayList<ParameterValue>();
if (manualCondition != null) {
List<ParameterDefinition> parameterDefinitions = manualCondition.getParameterDefinitions();
if (parameterDefinitions != null && !parameterDefinitions.isEmpty()) {
JSONArray a = JSONArray.fromObject(formData.get("parameter"));
for (Object o : a) {
JSONObject jo = (JSONObject) o;
String name = jo.getString("name");
ParameterDefinition d = manualCondition.getParameterDefinition(name);
if (d == null)
throw new IllegalArgumentException("No such parameter definition: " + name);
paramValues.add(d.createValue(req, jo));
}
}
}
}
if (paramValues == null) {
paramValues = new ArrayList<ParameterValue>();
}
Future<Promotion> f = process.scheduleBuild2(target, new UserCause(), paramValues);
if (f == null)
LOGGER.warning("Failing to schedule the promotion of " + target);
// TODO: we need better visual feed back so that the user knows that the build happened.
rsp.forwardToPreviousPage(req);
}
use of hudson.model.ParameterDefinition in project promoted-builds-plugin by jenkinsci.
the class PromotionProcessTest method testIsVisibleResolvesDefaultParameterValueIndirectly.
public void testIsVisibleResolvesDefaultParameterValueIndirectly() throws Exception {
FreeStyleProject project = createFreeStyleProject("project");
final List<ParameterDefinition> parameters = new ArrayList<ParameterDefinition>();
ParametersDefinitionProperty parametersProperty = new ParametersDefinitionProperty(parameters);
parameters.add(new StringParameterDefinition("IndirectVisibility", "false"));
parameters.add(new StringParameterDefinition("Visibility", "${IndirectVisibility}"));
project.addProperty(parametersProperty);
JobPropertyImpl jobProperty = new JobPropertyImpl(project);
project.addProperty(jobProperty);
PromotionProcess promotionProcess = jobProperty.addProcess("Promotion");
promotionProcess.isVisible = "${Visibility}";
assertFalse(promotionProcess.isVisible());
}
use of hudson.model.ParameterDefinition in project promoted-builds-plugin by jenkinsci.
the class ManualConditionBug22005 method testPromotionProcess.
public void testPromotionProcess() throws Exception {
FreeStyleProject p = createFreeStyleProject();
ExtensionList<Descriptor> list = hudson.getExtensionList(Descriptor.class);
list.add(new JobPropertyImpl.DescriptorImpl(JobPropertyImpl.class));
JobPropertyImpl base = new JobPropertyImpl(p);
p.addProperty(base);
PromotionProcess prom0 = createPromotionProcess(base, "PROM0");
ManualCondition prom0Condition = prom0.conditions.get(ManualCondition.class);
PromotionProcess prom1 = createPromotionProcess(base, "PROM1");
ManualCondition prom1Condition = prom1.conditions.get(ManualCondition.class);
PromotionProcess prom2 = createPromotionProcess(base, "PROM2");
ManualCondition prom2Condition = prom2.conditions.get(ManualCondition.class);
FreeStyleBuild b1 = assertBuildStatusSuccess(p.scheduleBuild2(0));
Promotion p0b1 = assertBuildStatusSuccess(prom0Condition.approve(b1, prom0));
assertEquals(2, p0b1.getParameterValues().size());
assertEquals(2, p0b1.getParameterDefinitionsWithValue().size());
Promotion p1b1 = assertBuildStatusSuccess(prom1Condition.approve(b1, prom1));
assertEquals(2, p1b1.getParameterValues().size());
assertEquals(2, p1b1.getParameterDefinitionsWithValue().size());
Promotion p2b1 = assertBuildStatusSuccess(prom2Condition.approve(b1, prom2));
assertEquals(2, p2b1.getParameterValues().size());
assertEquals(2, p2b1.getParameterDefinitionsWithValue().size());
List<ManualApproval> approvals = b1.getActions(ManualApproval.class);
assertEquals(3, approvals.size());
PromotedBuildAction promBuildAction = b1.getAction(PromotedBuildAction.class);
List<Status> statuses = promBuildAction.getPromotions();
assertEquals(3, statuses.size());
for (Status status : statuses) {
Promotion lastBuild = status.getLast();
List<ParameterDefinition> lastBuildParameters = lastBuild.getParameterDefinitionsWithValue();
assertEquals(2, lastBuildParameters.size());
}
}
Aggregations