Search in sources :

Example 21 with ParametersDefinitionProperty

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

the class SelfPromotionTest method testPromotionEnvironmentShouldIncludeTargetParameters.

@Issue("JENKINS-22679")
@Test
public // @Issue("JENKINS-34826") // Can be reproduced in Jenkins 2.3 +
void testPromotionEnvironmentShouldIncludeTargetParameters() throws Exception {
    String paramName = "param";
    FreeStyleProject p = j.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
    j.configRoundtrip(p);
    // rebind
    promotion = p.getProperty(JobPropertyImpl.class);
    promo1 = promotion.getItem("promo1");
    String paramValue = "someString";
    FreeStyleBuild b = j.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) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test)

Aggregations

ParametersDefinitionProperty (hudson.model.ParametersDefinitionProperty)21 Test (org.junit.Test)13 StringParameterDefinition (hudson.model.StringParameterDefinition)12 ParameterDefinition (hudson.model.ParameterDefinition)11 FreeStyleProject (hudson.model.FreeStyleProject)9 ParametersAction (hudson.model.ParametersAction)8 StringParameterValue (hudson.model.StringParameterValue)8 Issue (org.jvnet.hudson.test.Issue)7 ArrayList (java.util.ArrayList)6 ParameterValue (hudson.model.ParameterValue)5 BooleanParameterDefinition (hudson.model.BooleanParameterDefinition)4 ImmutableList (com.google.common.collect.ImmutableList)3 Shell (hudson.tasks.Shell)3 List (java.util.List)3 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 FreeStyleBuild (hudson.model.FreeStyleBuild)2 JobPropertyImpl (hudson.plugins.promoted_builds.JobPropertyImpl)2 Promotion (hudson.plugins.promoted_builds.Promotion)2 PromotionProcess (hudson.plugins.promoted_builds.PromotionProcess)2