Search in sources :

Example 11 with StringParameterValue

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

Example 12 with StringParameterValue

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

the class PromotionProcess method getDefaultParameterValuesAsEnvVars.

private static EnvVars getDefaultParameterValuesAsEnvVars(AbstractProject owner) {
    EnvVars envVars = null;
    ParametersDefinitionProperty parametersDefinitionProperty = (ParametersDefinitionProperty) owner.getProperty(ParametersDefinitionProperty.class);
    if (parametersDefinitionProperty != null) {
        envVars = new EnvVars();
        for (ParameterDefinition parameterDefinition : parametersDefinitionProperty.getParameterDefinitions()) {
            ParameterValue defaultParameterValue = parameterDefinition.getDefaultParameterValue();
            if (defaultParameterValue != null) {
                if (defaultParameterValue instanceof StringParameterValue) {
                    envVars.put(parameterDefinition.getName(), (String) defaultParameterValue.getValue());
                }
            }
        }
        EnvVars.resolve(envVars);
    }
    return envVars;
}
Also used : EnvVars(hudson.EnvVars) ParametersDefinitionProperty(hudson.model.ParametersDefinitionProperty) StringParameterValue(hudson.model.StringParameterValue) ParameterValue(hudson.model.ParameterValue) StringParameterValue(hudson.model.StringParameterValue) ParameterDefinition(hudson.model.ParameterDefinition)

Example 13 with StringParameterValue

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

the class PipelineApiTest method testPipelineQueue.

@Test
public void testPipelineQueue() throws Exception {
    FreeStyleProject p1 = j.createFreeStyleProject("pipeline1");
    p1.setConcurrentBuild(true);
    p1.addProperty(new ParametersDefinitionProperty(new StringParameterDefinition("test", "test")));
    p1.getBuildersList().add(new Shell("echo hello!\nsleep 300"));
    p1.scheduleBuild2(0).waitForStart();
    p1.scheduleBuild2(0).waitForStart();
    Jenkins.get().getQueue().schedule(p1, 0, new ParametersAction(new StringParameterValue("test", "test1")), new CauseAction(new Cause.UserIdCause()));
    Jenkins.get().getQueue().schedule(p1, 0, new ParametersAction(new StringParameterValue("test", "test2")), new CauseAction(new Cause.UserIdCause()));
    List queue = request().get("/organizations/jenkins/pipelines/pipeline1/queue").build(List.class);
    Assert.assertEquals(2, queue.size());
    Assert.assertEquals(4, ((Map) queue.get(0)).get("expectedBuildNumber"));
    Assert.assertEquals(3, ((Map) queue.get(1)).get("expectedBuildNumber"));
    Assert.assertEquals("Waiting for next available executor", ((Map) queue.get(0)).get("causeOfBlockage"));
    Assert.assertEquals("Waiting for next available executor", ((Map) queue.get(1)).get("causeOfBlockage"));
    Run r = QueueUtil.getRun(p1, Long.parseLong((String) ((Map) queue.get(0)).get("id")));
    // its not moved out of queue yet
    assertNull(r);
}
Also used : Shell(hudson.tasks.Shell) StringParameterDefinition(hudson.model.StringParameterDefinition) ParametersDefinitionProperty(hudson.model.ParametersDefinitionProperty) StringParameterValue(hudson.model.StringParameterValue) CauseAction(hudson.model.CauseAction) List(java.util.List) Run(hudson.model.Run) FreeStyleProject(hudson.model.FreeStyleProject) ParametersAction(hudson.model.ParametersAction) Test(org.junit.Test)

Aggregations

StringParameterValue (hudson.model.StringParameterValue)13 StringParameterDefinition (hudson.model.StringParameterDefinition)9 Test (org.junit.Test)9 ParametersDefinitionProperty (hudson.model.ParametersDefinitionProperty)8 ParametersAction (hudson.model.ParametersAction)6 Issue (org.jvnet.hudson.test.Issue)6 FreeStyleProject (hudson.model.FreeStyleProject)4 ParameterValue (hudson.model.ParameterValue)4 JobPropertyImpl (hudson.plugins.promoted_builds.JobPropertyImpl)4 Promotion (hudson.plugins.promoted_builds.Promotion)4 PromotionProcess (hudson.plugins.promoted_builds.PromotionProcess)4 FreeStyleBuild (hudson.model.FreeStyleBuild)3 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)3 EnvVars (hudson.EnvVars)2 BooleanParameterValue (hudson.model.BooleanParameterValue)2 ParameterDefinition (hudson.model.ParameterDefinition)2 Action (hudson.model.Action)1 BooleanParameterDefinition (hudson.model.BooleanParameterDefinition)1 CauseAction (hudson.model.CauseAction)1 Descriptor (hudson.model.Descriptor)1