Search in sources :

Example 1 with ParametersAction

use of hudson.model.ParametersAction 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 2 with ParametersAction

use of hudson.model.ParametersAction 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 BlueQueueItem 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.getInstance().getQueue().schedule2((Queue.Task) job, 0, new ParametersAction(parameterValues), new CauseAction(new Cause.UserIdCause()));
        } else {
            scheduleResult = Jenkins.getInstance().getQueue().schedule2((Queue.Task) job, 0, new CauseAction(new Cause.UserIdCause()));
        }
        if (scheduleResult.isAccepted()) {
            final Queue.Item item = scheduleResult.getItem();
            return new QueueItemImpl(item, job.getName(), expectedBuildNumber, pipeline.getLink().rel("queue").rel(Long.toString(item.getId())), pipeline.getLink());
        } 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 3 with ParametersAction

use of hudson.model.ParametersAction 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)

Example 4 with ParametersAction

use of hudson.model.ParametersAction in project promoted-builds-plugin by jenkinsci.

the class SelfPromotionInheritanceTest method testPromotionEnvironmentShouldIncludeTargetParameters.

@Test
@Bug(22679)
public void testPromotionEnvironmentShouldIncludeTargetParameters() throws Exception {
    String paramName = "param";
    InheritanceProjectsPair inheritanceProjectPair = j.createInheritanceProjectDerivedWithBase();
    // promote if the downstream passes
    JobPropertyImpl promotion = new JobPropertyImpl(inheritanceProjectPair.getBase());
    inheritanceProjectPair.getBase().addProperty(promotion);
    // TODO review this property asignment after https://issues.jenkins-ci.org/browse/JENKINS-34831 is fixed
    inheritanceProjectPair.getBase().addProperty(new ParametersDefinitionProperty(new StringParameterDefinition(paramName, "")));
    inheritanceProjectPair.getDerived().addProperty(new ParametersDefinitionProperty(new StringParameterDefinition(paramName, "")));
    PromotionProcess promo1 = promotion.addProcess("promo1");
    promo1.conditions.add(new SelfPromotionCondition(false));
    // fire ItemListeners, this includes ArtifactArchiver,Migrator to make this test compatible with jenkins 1.575+
    fireItemListeners();
    String paramValue = "someString";
    j.assertBuildStatusSuccess(inheritanceProjectPair.getDerived().scheduleBuild2(0, new Cause.UserCause(), new ParametersAction(new StringParameterValue(paramName, paramValue))));
    // internally, the promotion is still an asynchronous process. It just happens
    // right away after the build is complete.
    j.waitUntilNoActivity();
    // rebind
    promotion = inheritanceProjectPair.getDerived().getProperty(JobPropertyImpl.class, /*Forcing inheritance as temporary hack for inheritance plugin 1.53 
                because that version of the plugin uses inheritance only for certain predefined cases: 
                -specific methods on the call stack
                -url paths.
                This has been changed as pull request https://github.com/i-m-c/jenkins-inheritance-plugin/pull/40
               */
    IMode.INHERIT_FORCED);
    promo1 = promotion.getItem("promo1");
    // verify that the promotion's environment contains the parameter from the target build.
    Promotion pb = promo1.getBuildByNumber(1);
    assertEquals(paramValue, pb.getEnvironment(TaskListener.NULL).get(paramName, null));
}
Also used : InheritanceProjectsPair(hudson.plugins.promoted_builds.inheritance.helpers.InheritanceProjectsPair) StringParameterDefinition(hudson.model.StringParameterDefinition) ParametersDefinitionProperty(hudson.model.ParametersDefinitionProperty) PromotionProcess(hudson.plugins.promoted_builds.PromotionProcess) StringParameterValue(hudson.model.StringParameterValue) SelfPromotionCondition(hudson.plugins.promoted_builds.conditions.SelfPromotionCondition) JobPropertyImpl(hudson.plugins.promoted_builds.JobPropertyImpl) Promotion(hudson.plugins.promoted_builds.Promotion) ParametersAction(hudson.model.ParametersAction) Test(org.junit.Test) Bug(org.jvnet.hudson.test.Bug)

Example 5 with ParametersAction

use of hudson.model.ParametersAction in project promoted-builds-plugin by jenkinsci.

the class SelfPromotionTest method testPromotionEnvironmentShouldIncludeTargetParameters.

@Bug(22679)
public // @Bug(34826) // Can be reproduced in Jenkins 2.3 +
void testPromotionEnvironmentShouldIncludeTargetParameters() throws Exception {
    String paramName = "param";
    FreeStyleProject p = createFreeStyleProject();
    p.addProperty(new ParametersDefinitionProperty(new StringParameterDefinition(paramName, "")));
    // promote if the downstream passes
    JobPropertyImpl promotion = new JobPropertyImpl(p);
    p.addProperty(promotion);
    PromotionProcess promo1 = promotion.addProcess("promo1");
    promo1.conditions.add(new SelfPromotionCondition(false));
    // ensure that the data survives the roundtrip
    configRoundtrip(p);
    // rebind
    promotion = p.getProperty(JobPropertyImpl.class);
    promo1 = promotion.getItem("promo1");
    String paramValue = "someString";
    FreeStyleBuild b = assertBuildStatusSuccess(p.scheduleBuild2(0, new Cause.UserCause(), new ParametersAction(new StringParameterValue(paramName, paramValue))));
    // internally, the promotion is still an asynchronous process. It just happens
    // right away after the build is complete.
    Thread.sleep(1000);
    // verify that the promotion's environment contains the parameter from the target build.
    Promotion pb = promo1.getBuildByNumber(1);
    assertEquals(paramValue, pb.getEnvironment(TaskListener.NULL).get(paramName, null));
}
Also used : StringParameterDefinition(hudson.model.StringParameterDefinition) ParametersDefinitionProperty(hudson.model.ParametersDefinitionProperty) PromotionProcess(hudson.plugins.promoted_builds.PromotionProcess) StringParameterValue(hudson.model.StringParameterValue) FreeStyleBuild(hudson.model.FreeStyleBuild) FreeStyleProject(hudson.model.FreeStyleProject) JobPropertyImpl(hudson.plugins.promoted_builds.JobPropertyImpl) Promotion(hudson.plugins.promoted_builds.Promotion) ParametersAction(hudson.model.ParametersAction) Bug(org.jvnet.hudson.test.Bug)

Aggregations

ParametersAction (hudson.model.ParametersAction)6 ParametersDefinitionProperty (hudson.model.ParametersDefinitionProperty)4 ParameterValue (hudson.model.ParameterValue)3 StringParameterDefinition (hudson.model.StringParameterDefinition)3 StringParameterValue (hudson.model.StringParameterValue)3 CauseAction (hudson.model.CauseAction)2 FreeStyleProject (hudson.model.FreeStyleProject)2 JobPropertyImpl (hudson.plugins.promoted_builds.JobPropertyImpl)2 Promotion (hudson.plugins.promoted_builds.Promotion)2 PromotionProcess (hudson.plugins.promoted_builds.PromotionProcess)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 Bug (org.jvnet.hudson.test.Bug)2 ImmutableList (com.google.common.collect.ImmutableList)1 AbortException (hudson.AbortException)1 AbstractBuild (hudson.model.AbstractBuild)1 Cause (hudson.model.Cause)1 FreeStyleBuild (hudson.model.FreeStyleBuild)1 ParameterDefinition (hudson.model.ParameterDefinition)1 Queue (hudson.model.Queue)1