Search in sources :

Example 56 with FreeStyleProject

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

the class SelfPromotionTest method testFailure.

public void testFailure() throws Exception {
    FreeStyleProject p = createFreeStyleProject();
    // promote if the downstream passes
    JobPropertyImpl promotion = new JobPropertyImpl(p);
    p.addProperty(promotion);
    PromotionProcess promo1 = promotion.addProcess("promo1");
    promo1.conditions.add(new SelfPromotionCondition(false));
    PromotionProcess promo2 = promotion.addProcess("promo2");
    promo2.conditions.add(new SelfPromotionCondition(true));
    // ensure that the data survives the roundtrip
    configRoundtrip(p);
    // rebind
    promotion = p.getProperty(JobPropertyImpl.class);
    promo1 = promotion.getItem("promo1");
    promo2 = promotion.getItem("promo2");
    p.getBuildersList().add(failureBuilder());
    FreeStyleBuild b = assertBuildStatus(Result.FAILURE, p.scheduleBuild2(0).get());
    // internally, the promotion is still an asynchronous process. It just happens
    // right away after the build is complete.
    Thread.sleep(1000);
    // verify that neither promotions happened
    assertTrue("promo1 did not occur", promo1.getBuilds().isEmpty());
    assertTrue("promo2 did not occur", promo2.getBuilds().isEmpty());
    PromotedBuildAction badge = (PromotedBuildAction) b.getBadgeActions().get(0);
    assertFalse(badge.contains(promo1));
    assertFalse(badge.contains(promo2));
}
Also used : PromotionProcess(hudson.plugins.promoted_builds.PromotionProcess) FreeStyleBuild(hudson.model.FreeStyleBuild) PromotedBuildAction(hudson.plugins.promoted_builds.PromotedBuildAction) FreeStyleProject(hudson.model.FreeStyleProject) JobPropertyImpl(hudson.plugins.promoted_builds.JobPropertyImpl)

Example 57 with FreeStyleProject

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

the class SelfPromotionTest method testBasic.

public void testBasic() throws Exception {
    FreeStyleProject p = createFreeStyleProject();
    // promote if the downstream passes
    JobPropertyImpl promotion = new JobPropertyImpl(p);
    p.addProperty(promotion);
    PromotionProcess promo1 = promotion.addProcess("promo1");
    promo1.conditions.add(new SelfPromotionCondition(false));
    PromotionProcess promo2 = promotion.addProcess("promo2");
    promo2.conditions.add(new SelfPromotionCondition(false));
    // ensure that the data survives the roundtrip
    configRoundtrip(p);
    // rebind
    promotion = p.getProperty(JobPropertyImpl.class);
    promo1 = promotion.getItem("promo1");
    promo2 = promotion.getItem("promo2");
    FreeStyleBuild b = assertBuildStatusSuccess(p.scheduleBuild2(0));
    // internally, the promotion is still an asynchronous process. It just happens
    // right away after the build is complete.
    Thread.sleep(1000);
    // verify that both promotions happened
    Promotion pb = promo1.getBuilds().get(0);
    assertSame(pb.getTarget(), b);
    pb = promo2.getBuilds().get(0);
    assertSame(pb.getTarget(), b);
    PromotedBuildAction badge = (PromotedBuildAction) b.getBadgeActions().get(0);
    assertTrue(badge.contains(promo1));
    assertTrue(badge.contains(promo2));
}
Also used : PromotionProcess(hudson.plugins.promoted_builds.PromotionProcess) FreeStyleBuild(hudson.model.FreeStyleBuild) PromotedBuildAction(hudson.plugins.promoted_builds.PromotedBuildAction) FreeStyleProject(hudson.model.FreeStyleProject) JobPropertyImpl(hudson.plugins.promoted_builds.JobPropertyImpl) Promotion(hudson.plugins.promoted_builds.Promotion)

Example 58 with FreeStyleProject

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

Example 59 with FreeStyleProject

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

the class PromotionProcessTest method testIsVisibleTrueReturnsVisible.

public void testIsVisibleTrueReturnsVisible() throws Exception {
    FreeStyleProject project = createFreeStyleProject("project");
    JobPropertyImpl jobProperty = new JobPropertyImpl(project);
    project.addProperty(jobProperty);
    PromotionProcess promotionProcess = jobProperty.addProcess("Promotion");
    promotionProcess.isVisible = "true";
    assertTrue(promotionProcess.isVisible());
}
Also used : FreeStyleProject(hudson.model.FreeStyleProject)

Example 60 with FreeStyleProject

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

the class PromotionProcessTest method testIsVisibleResolvesDefaultParameterValue.

public void testIsVisibleResolvesDefaultParameterValue() throws Exception {
    FreeStyleProject project = createFreeStyleProject("project");
    final List<ParameterDefinition> parameters = new ArrayList<ParameterDefinition>();
    ParametersDefinitionProperty parametersProperty = new ParametersDefinitionProperty(parameters);
    parameters.add(new StringParameterDefinition("Visibility", "false"));
    project.addProperty(parametersProperty);
    JobPropertyImpl jobProperty = new JobPropertyImpl(project);
    project.addProperty(jobProperty);
    PromotionProcess promotionProcess = jobProperty.addProcess("Promotion");
    promotionProcess.isVisible = "${Visibility}";
    assertFalse(promotionProcess.isVisible());
}
Also used : StringParameterDefinition(hudson.model.StringParameterDefinition) ParametersDefinitionProperty(hudson.model.ParametersDefinitionProperty) ArrayList(java.util.ArrayList) FreeStyleProject(hudson.model.FreeStyleProject) StringParameterDefinition(hudson.model.StringParameterDefinition) ParameterDefinition(hudson.model.ParameterDefinition)

Aggregations

FreeStyleProject (hudson.model.FreeStyleProject)88 Test (org.junit.Test)61 FreeStyleBuild (hudson.model.FreeStyleBuild)42 Shell (hudson.tasks.Shell)21 Map (java.util.Map)20 ImmutableMap (com.google.common.collect.ImmutableMap)17 JobPropertyImpl (hudson.plugins.promoted_builds.JobPropertyImpl)14 PromotionProcess (hudson.plugins.promoted_builds.PromotionProcess)13 ArrayList (java.util.ArrayList)12 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)11 StringParameterDefinition (hudson.model.StringParameterDefinition)10 MockFolder (org.jvnet.hudson.test.MockFolder)10 List (java.util.List)9 PromotedBuildAction (hudson.plugins.promoted_builds.PromotedBuildAction)8 ImmutableList (com.google.common.collect.ImmutableList)7 FreeStyleProjectMock (hudson.model.FreeStyleProjectMock)7 Promotion (hudson.plugins.promoted_builds.Promotion)7 ParametersDefinitionProperty (hudson.model.ParametersDefinitionProperty)6 Run (hudson.model.Run)6 ManualCondition (hudson.plugins.promoted_builds.conditions.ManualCondition)6