use of hudson.model.ParameterDefinition in project promoted-builds-plugin by jenkinsci.
the class PromotionProcessTest method testIsVisibleResolvesDefaultParameterValue.
public void testIsVisibleResolvesDefaultParameterValue() throws Exception {
FreeStyleProject project = createFreeStyleProject("project");
final List<ParameterDefinition> parameters = new ArrayList<ParameterDefinition>();
ParametersDefinitionProperty parametersProperty = new ParametersDefinitionProperty(parameters);
parameters.add(new StringParameterDefinition("Visibility", "false"));
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 blueocean-plugin by jenkinsci.
the class AbstractPipelineImpl method getParameterDefinitions.
public static List<Object> getParameterDefinitions(Job job) {
ParametersDefinitionProperty pp = (ParametersDefinitionProperty) job.getProperty(ParametersDefinitionProperty.class);
List<Object> pds = new ArrayList<>();
if (pp != null) {
for (ParameterDefinition pd : pp.getParameterDefinitions()) {
pds.add(pd);
}
}
return pds;
}
use of hudson.model.ParameterDefinition 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.BadRequestExpception("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.BadRequestExpception("parameters.name is required element");
}
ParameterDefinition pd = pp.getParameterDefinition(name);
if (pd == null) {
throw new ServiceException.BadRequestExpception("No such parameter definition: " + name);
}
ParameterValue parameterValue = pd.createValue(request, p);
if (parameterValue != null) {
values.add(parameterValue);
pdsInRequest.add(pd);
} else {
throw new ServiceException.BadRequestExpception("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.BadRequestExpception("Missing parameter: " + pd.getName());
}
values.add(v);
}
}
}
}
} catch (IOException e) {
throw new ServiceException.UnexpectedErrorException(e.getMessage(), e);
}
return values;
}
use of hudson.model.ParameterDefinition 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(), ((StringParameterValue) defaultParameterValue).value);
}
}
}
EnvVars.resolve(envVars);
}
return envVars;
}
use of hudson.model.ParameterDefinition in project promoted-builds-plugin by jenkinsci.
the class ManualCondition method doApprove.
/**
* Web method to handle the approval action submitted by the user.
*/
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("../../../..");
}
Aggregations