Search in sources :

Example 1 with ParameterValue

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);
                }
            }
        }
    }
}
Also used : ParametersDefinitionProperty(hudson.model.ParametersDefinitionProperty) StringParameterValue(hudson.model.StringParameterValue) ParameterValue(hudson.model.ParameterValue) StringParameterValue(hudson.model.StringParameterValue) ParameterDefinition(hudson.model.ParameterDefinition)

Example 2 with ParameterValue

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;
}
Also used : Jenkins(jenkins.model.Jenkins) EnvVars(hudson.EnvVars) ParameterValue(hudson.model.ParameterValue) NodeProperty(hudson.slaves.NodeProperty) ParametersAction(hudson.model.ParametersAction)

Example 3 with ParameterValue

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);
}
Also used : ManualApproval(hudson.plugins.promoted_builds.conditions.ManualCondition.ManualApproval) StringParameterValue(hudson.model.StringParameterValue) ParameterValue(hudson.model.ParameterValue) ArrayList(java.util.ArrayList) CheckForNull(javax.annotation.CheckForNull)

Example 4 with ParameterValue

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);
}
Also used : ParameterValue(hudson.model.ParameterValue) UserCause(hudson.model.Cause.UserCause) JSONArray(net.sf.json.JSONArray) ManualCondition(hudson.plugins.promoted_builds.conditions.ManualCondition) JSONObject(net.sf.json.JSONObject) JSONNull(net.sf.json.JSONNull) JSONObject(net.sf.json.JSONObject) AbortException(hudson.AbortException) ParameterDefinition(hudson.model.ParameterDefinition) POST(org.kohsuke.stapler.verb.POST)

Example 5 with ParameterValue

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();
}
Also used : ManualCondition(hudson.plugins.promoted_builds.conditions.ManualCondition) ParameterValue(hudson.model.ParameterValue) ArrayList(java.util.ArrayList) ParametersAction(hudson.model.ParametersAction)

Aggregations

ParameterValue (hudson.model.ParameterValue)20 ParameterDefinition (hudson.model.ParameterDefinition)9 ManualCondition (hudson.plugins.promoted_builds.conditions.ManualCondition)7 ArrayList (java.util.ArrayList)7 ParametersAction (hudson.model.ParametersAction)6 StringParameterValue (hudson.model.StringParameterValue)6 Test (org.junit.Test)6 FreeStyleBuild (hudson.model.FreeStyleBuild)5 FreeStyleProject (hudson.model.FreeStyleProject)5 ParametersDefinitionProperty (hudson.model.ParametersDefinitionProperty)5 ManualApproval (hudson.plugins.promoted_builds.conditions.ManualCondition.ManualApproval)5 EnvVars (hudson.EnvVars)4 StringParameterDefinition (hudson.model.StringParameterDefinition)4 JobPropertyImpl (hudson.plugins.promoted_builds.JobPropertyImpl)4 PromotionProcess (hudson.plugins.promoted_builds.PromotionProcess)4 JSONObject (net.sf.json.JSONObject)4 Action (hudson.model.Action)3 Descriptor (hudson.model.Descriptor)3 PromotedBuildAction (hudson.plugins.promoted_builds.PromotedBuildAction)3 JSONArray (net.sf.json.JSONArray)3