Search in sources :

Example 11 with ParameterValue

use of hudson.model.ParameterValue 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;
}
Also used : ParametersDefinitionProperty(hudson.model.ParametersDefinitionProperty) ParameterValue(hudson.model.ParameterValue) AbstractBuild(hudson.model.AbstractBuild) ArrayList(java.util.ArrayList) ParametersAction(hudson.model.ParametersAction) AbortException(hudson.AbortException) ParameterDefinition(hudson.model.ParameterDefinition)

Example 12 with ParameterValue

use of hudson.model.ParameterValue 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<>();
    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.BadRequestException("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.BadRequestException("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.getAuthentication2();
        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;
    }
}
Also used : JSONObject(net.sf.json.JSONObject) ServiceException(io.jenkins.blueocean.commons.ServiceException) FileParameterValue(hudson.model.FileParameterValue) ParameterValue(hudson.model.ParameterValue) HashMap(java.util.HashMap) Authentication(org.springframework.security.core.Authentication) InputStep(org.jenkinsci.plugins.workflow.support.steps.input.InputStep) BlueInputStep(io.jenkins.blueocean.rest.model.BlueInputStep) JSONObject(net.sf.json.JSONObject) ParameterDefinition(hudson.model.ParameterDefinition)

Example 13 with ParameterValue

use of hudson.model.ParameterValue in project blueocean-plugin by jenkinsci.

the class RunContainerImpl method create.

/**
 * Schedules a build. If build already exists in the queue and the pipeline does not
 * support running multiple builds at the same time, return a reference to the existing
 * build.
 *
 * @return Queue item.
 */
@Override
public BlueRun create(StaplerRequest request) {
    job.checkPermission(Item.BUILD);
    if (job instanceof Queue.Task) {
        ScheduleResult scheduleResult;
        List<ParameterValue> parameterValues = getParameterValue(request);
        int expectedBuildNumber = job.getNextBuildNumber();
        if (parameterValues.size() > 0) {
            scheduleResult = Jenkins.get().getQueue().schedule2((Queue.Task) job, 0, new ParametersAction(parameterValues), new CauseAction(new Cause.UserIdCause()));
        } else {
            scheduleResult = Jenkins.get().getQueue().schedule2((Queue.Task) job, 0, new CauseAction(new Cause.UserIdCause()));
        }
        // Keep FB happy.
        // scheduleResult.getItem() will always return non-null if scheduleResult.isAccepted() is true
        final Queue.Item item = scheduleResult.getItem();
        if (scheduleResult.isAccepted() && item != null) {
            return new QueueItemImpl(pipeline.getOrganization(), item, pipeline, expectedBuildNumber, pipeline.getLink().rel("queue").rel(Long.toString(item.getId())), pipeline.getLink()).toRun();
        } else {
            throw new ServiceException.UnexpectedErrorException("Queue item request was not accepted");
        }
    } else {
        throw new ServiceException.NotImplementedException("This pipeline type does not support being queued.");
    }
}
Also used : ScheduleResult(hudson.model.queue.ScheduleResult) ParameterValue(hudson.model.ParameterValue) ParametersAction(hudson.model.ParametersAction) Cause(hudson.model.Cause) CauseAction(hudson.model.CauseAction) Queue(hudson.model.Queue)

Example 14 with ParameterValue

use of hudson.model.ParameterValue in project workflow-cps-plugin by jenkinsci.

the class ParamsVariable method getValue.

@SuppressWarnings("unchecked")
@Override
public Object getValue(CpsScript script) throws Exception {
    Run<?, ?> b = script.$build();
    if (b == null) {
        throw new IllegalStateException("cannot find owning build");
    }
    // Could extend AbstractMap and make a Serializable lazy wrapper, but getValue impls seem cheap anyway.
    Map<String, Object> values = new HashMap<>();
    ParametersAction action = b.getAction(ParametersAction.class);
    if (action != null) {
        List<ParameterValue> parameterValues;
        try {
            // TODO 1.651.2+ remove reflection
            parameterValues = (List<ParameterValue>) ParametersAction.class.getMethod("getAllParameters").invoke(action);
        } catch (NoSuchMethodException x) {
            parameterValues = action.getParameters();
        }
        for (ParameterValue parameterValue : parameterValues) {
            addValue(values, parameterValue);
        }
    }
    ParametersDefinitionProperty prop = b.getParent().getProperty(ParametersDefinitionProperty.class);
    if (prop != null) {
        // JENKINS-35698: look for default values as well
        for (ParameterDefinition param : prop.getParameterDefinitions()) {
            if (!values.containsKey(param.getName())) {
                ParameterValue defaultParameterValue = param.getDefaultParameterValue();
                if (defaultParameterValue != null) {
                    addValue(values, defaultParameterValue);
                }
            }
        }
    }
    return Collections.unmodifiableMap(values);
}
Also used : ParameterValue(hudson.model.ParameterValue) ParametersDefinitionProperty(hudson.model.ParametersDefinitionProperty) HashMap(java.util.HashMap) ParametersAction(hudson.model.ParametersAction) ParameterDefinition(hudson.model.ParameterDefinition)

Example 15 with ParameterValue

use of hudson.model.ParameterValue in project selenium_java by sergueik.

the class BuildDetailsResolver method addParametersFromContext.

private static void addParametersFromContext(BuildDetailsImpl details, Run<?, ?> run) throws IOException, InterruptedException {
    LOGGER.finest("resolving build parameters");
    List<BuildParameter> buildParameters = new ArrayList<BuildParameter>();
    for (Action action : run.getAllActions()) {
        if (!ParametersAction.class.isInstance(action)) {
            continue;
        }
        ParametersAction paramAction = (ParametersAction) action;
        for (ParameterValue param : paramAction.getParameters()) {
            LOGGER.finest("found parameter: " + param);
            String paramId = run.getId() + "-" + param.getName();
            buildParameters.add(new BuildParameterImpl(paramId, param.getName(), param.getValue().toString(), details));
        }
    }
    details.setParameters(buildParameters);
}
Also used : BuildParameter(org.jenkins.plugins.audit2db.model.BuildParameter) Action(hudson.model.Action) ParametersAction(hudson.model.ParametersAction) ParameterValue(hudson.model.ParameterValue) ArrayList(java.util.ArrayList) BuildParameterImpl(org.jenkins.plugins.audit2db.internal.model.BuildParameterImpl) 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