use of hudson.model.ParameterValue in project generic-webhook-trigger-plugin by jenkinsci.
the class GenericTrigger method addAllParametersFromParameterizedJob.
/**
* To keep any default values set there.
*/
private void addAllParametersFromParameterizedJob(final Job<?, ?> job, final List<StringParameterValue> parameterList) {
final ParametersDefinitionProperty parametersDefinitionProperty = job.getProperty(ParametersDefinitionProperty.class);
if (parametersDefinitionProperty != null) {
for (final ParameterDefinition parameterDefinition : parametersDefinitionProperty.getParameterDefinitions()) {
final String param = parameterDefinition.getName();
final ParameterValue defaultParameterValue = parameterDefinition.getDefaultParameterValue();
if (defaultParameterValue != null) {
final String value = defaultParameterValue.getValue().toString();
if (!isNullOrEmpty(value)) {
final StringParameterValue parameter = new StringParameterValue(param, value);
parameterList.add(parameter);
}
}
}
}
}
use of hudson.model.ParameterValue in project workflow-job-plugin by jenkinsci.
the class WorkflowRun method getEnvironment.
@Override
public EnvVars getEnvironment(TaskListener listener) throws IOException, InterruptedException {
EnvVars env = super.getEnvironment(listener);
Jenkins instance = Jenkins.getInstance();
if (instance != null) {
for (NodeProperty nodeProperty : instance.getGlobalNodeProperties()) {
nodeProperty.buildEnvVars(env, listener);
}
}
// TODO EnvironmentContributingAction does not support Job yet:
ParametersAction a = getAction(ParametersAction.class);
if (a != null) {
for (ParameterValue v : a) {
v.buildEnvironment(this, env);
}
}
EnvVars.resolve(env);
return env;
}
use of hudson.model.ParameterValue in project promoted-builds-plugin by jenkinsci.
the class PromotionProcess method considerPromotion2.
/**
* Checks if the build is promotable, and if so, promote it.
*
* @param build Build to be promoted
* @return
* {@code null} if the build was not promoted, otherwise Future that kicks in when the build is completed.
* @throws IOException
*/
@CheckForNull
public Future<Promotion> considerPromotion2(AbstractBuild<?, ?> build) throws IOException {
LOGGER.fine("Considering the promotion of " + build + " via " + getName() + " without parmeters");
// If the build has manual approvals, use the parameters from it
List<ParameterValue> params = new ArrayList<ParameterValue>();
List<ManualApproval> approvals = build.getActions(ManualApproval.class);
for (ManualApproval approval : approvals) {
if (approval.name.equals(getName())) {
LOGGER.fine("Getting parameters from existing manual promotion");
params = approval.badge.getParameterValues();
LOGGER.finer("Using paramters: " + params.toString());
}
}
return considerPromotion2(build, params);
}
use of hudson.model.ParameterValue 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
*/
@POST
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());
// TODO: Use PromotionPermissionHelper.checkPermission instead, but consider issues with backwards compatibility.
if (!PromotionPermissionHelper.hasPermission(target.getProject(), manualCondition)) {
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) {
final JSONObject jo;
if (o instanceof JSONObject) {
jo = (JSONObject) o;
} else if (o instanceof JSONNull) {
// ignore nulls
continue;
} else {
throw new IllegalArgumentException("Array type is not supported " + 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.ParameterValue in project promoted-builds-plugin by jenkinsci.
the class Promotion method getParameterValues.
public List<ParameterValue> getParameterValues() {
List<ParameterValue> values = new ArrayList<ParameterValue>();
ParametersAction parametersAction = getParametersActions(this);
if (parametersAction != null) {
ManualCondition manualCondition = (ManualCondition) getProject().getPromotionCondition(ManualCondition.class.getName());
if (manualCondition != null) {
for (ParameterValue pvalue : parametersAction.getParameters()) {
if (manualCondition.getParameterDefinition(pvalue.getName()) != null) {
values.add(pvalue);
}
}
}
return values;
}
// fallback to badge lookup for compatibility
for (PromotionBadge badget : getStatus().getBadges()) {
if (badget instanceof ManualCondition.Badge) {
return ((ManualCondition.Badge) badget).getParameterValues();
}
}
return Collections.emptyList();
}
Aggregations