use of hudson.model.ParameterValue in project promoted-builds-plugin by jenkinsci.
the class ManualConditionTest method testManualPromotionProcessWithInvalidParam.
@Issue("SECURITY-170")
@Test
public /**
* Verify that the plugin is tolerant against SECURITY-170 in Manual conditions
*/
void testManualPromotionProcessWithInvalidParam() throws Exception {
FreeStyleProject p = j.createFreeStyleProject();
ExtensionList<Descriptor> list = j.jenkins.getExtensionList(Descriptor.class);
list.add(new JobPropertyImpl.DescriptorImpl(JobPropertyImpl.class));
JobPropertyImpl base = new JobPropertyImpl(p);
p.addProperty(base);
PromotionProcess foo = base.addProcess("foo");
ManualCondition condition = new ManualCondition();
condition.getParameterDefinitions().add(new StringParameterDefinition("FOO", "BAR", "Test parameter"));
foo.conditions.add(condition);
FreeStyleBuild b1 = j.assertBuildStatusSuccess(p.scheduleBuild2(0));
// Promote a build. Also add one invalid parameter
List<ParameterValue> paramValues = condition.createDefaultValues();
paramValues.add(new StringParameterValue("INVALID_PARAM", "hacked!"));
j.assertBuildStatusSuccess(condition.approve(b1, foo, paramValues));
ManualApproval manualApproval = b1.getAction(ManualApproval.class);
assertNotNull(manualApproval);
List<ParameterValue> parameterValues = manualApproval.badge.getParameterValues();
// Verify that the build succeeds && has no INVALID_PARAM
PromotedBuildAction statuses = b1.getAction(PromotedBuildAction.class);
assertNotNull(statuses);
assertNotNull(statuses.getPromotions());
assertFalse(statuses.getPromotions().isEmpty());
Promotion pb = base.getItem("foo").getBuildByNumber(1);
assertNotNull("INVALID_PARAM should not be injected into the environment", pb.getEnvironment(TaskListener.NULL).get("INVALID_PARAM", null));
}
use of hudson.model.ParameterValue in project promoted-builds-plugin by jenkinsci.
the class PromotionTargetActionTest method test1.
/**
* When a project is created, built, and renamed, then the old build is created,
* that results in NPE.
*/
@Test
public void test1() throws Exception {
FreeStyleProject up = j.createFreeStyleProject("up");
up.setCustomWorkspace(j.createTmpDir().getPath());
// promote if the downstream passes
JobPropertyImpl promotion = new JobPropertyImpl(up);
up.addProperty(promotion);
PromotionProcess proc = promotion.addProcess("promo");
proc.conditions.add(new ManualCondition());
FreeStyleBuild b = j.assertBuildStatusSuccess(up.scheduleBuild2(0));
b.addAction(new ManualApproval(proc.getName(), Collections.<ParameterValue>emptyList()));
b.save();
// check for promotion
Promotion p = j.assertBuildStatusSuccess(proc.considerPromotion2(b));
up.renameTo("up2");
assertSame(b, p.getTargetBuildOrFail());
}
use of hudson.model.ParameterValue in project promoted-builds-plugin by jenkinsci.
the class ManualCondition method doApprove.
/**
* Web method to handle the approval action submitted by the user.
*/
@POST
public void doApprove(StaplerRequest req, StaplerResponse rsp, @AncestorInPath PromotionProcess promotionProcess, @AncestorInPath AbstractBuild<?, ?> build) throws IOException, ServletException {
JSONObject formData = req.getSubmittedForm();
if (canApprove(promotionProcess, build)) {
List<ParameterValue> paramValues = new ArrayList<ParameterValue>();
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 = getParameterDefinition(name);
if (d == null)
throw new IllegalArgumentException("No such parameter definition: " + name);
paramValues.add(d.createValue(req, jo));
}
}
approve(build, promotionProcess, paramValues);
}
rsp.sendRedirect2("../../../..");
}
use of hudson.model.ParameterValue in project promoted-builds-plugin by jenkinsci.
the class PromotionProcess method getDefaultParameterValuesAsEnvVars.
private static EnvVars getDefaultParameterValuesAsEnvVars(AbstractProject owner) {
EnvVars envVars = null;
ParametersDefinitionProperty parametersDefinitionProperty = (ParametersDefinitionProperty) owner.getProperty(ParametersDefinitionProperty.class);
if (parametersDefinitionProperty != null) {
envVars = new EnvVars();
for (ParameterDefinition parameterDefinition : parametersDefinitionProperty.getParameterDefinitions()) {
ParameterValue defaultParameterValue = parameterDefinition.getDefaultParameterValue();
if (defaultParameterValue != null) {
if (defaultParameterValue instanceof StringParameterValue) {
envVars.put(parameterDefinition.getName(), (String) defaultParameterValue.getValue());
}
}
}
EnvVars.resolve(envVars);
}
return envVars;
}
use of hudson.model.ParameterValue in project blueocean-plugin by jenkinsci.
the class RunContainerImpl method getParameterValue.
private List<ParameterValue> getParameterValue(@NonNull StaplerRequest request) {
List<ParameterValue> values = new ArrayList<>();
List<ParameterDefinition> pdsInRequest = new ArrayList<>();
ParametersDefinitionProperty pp = (ParametersDefinitionProperty) job.getProperty(ParametersDefinitionProperty.class);
if (pp == null) {
return values;
}
try {
JSONObject body = JSONObject.fromObject(IOUtils.toString(request.getReader()));
if (body.get("parameters") == null && pp.getParameterDefinitions().size() > 0) {
throw new ServiceException.BadRequestException("This is parameterized job, requires parameters");
}
if (body.get("parameters") != null) {
JSONArray pds = JSONArray.fromObject(body.get("parameters"));
for (Object o : pds) {
JSONObject p = (JSONObject) o;
String name = (String) p.get("name");
if (name == null) {
throw new ServiceException.BadRequestException("parameters.name is required element");
}
ParameterDefinition pd = pp.getParameterDefinition(name);
if (pd == null) {
throw new ServiceException.BadRequestException("No such parameter definition: " + name);
}
ParameterValue parameterValue = pd.createValue(request, p);
if (parameterValue != null) {
values.add(parameterValue);
pdsInRequest.add(pd);
} else {
throw new ServiceException.BadRequestException("Invalid value. Cannot retrieve the parameter value: " + name);
}
}
// now check for missing parameters without default values
if (pdsInRequest.size() != pp.getParameterDefinitions().size()) {
for (ParameterDefinition pd : pp.getParameterDefinitions()) {
if (!pdsInRequest.contains(pd)) {
ParameterValue v = pd.getDefaultParameterValue();
if (v == null || v.getValue() == null) {
throw new ServiceException.BadRequestException("Missing parameter: " + pd.getName());
}
values.add(v);
}
}
}
}
} catch (IOException e) {
throw new ServiceException.UnexpectedErrorException(e.getMessage(), e);
}
return values;
}
Aggregations