Search in sources :

Example 16 with FreeStyleBuild

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

the class ManualConditionBug22005 method testPromotionProcess.

public void testPromotionProcess() throws Exception {
    FreeStyleProject p = createFreeStyleProject();
    ExtensionList<Descriptor> list = hudson.getExtensionList(Descriptor.class);
    list.add(new JobPropertyImpl.DescriptorImpl(JobPropertyImpl.class));
    JobPropertyImpl base = new JobPropertyImpl(p);
    p.addProperty(base);
    PromotionProcess prom0 = createPromotionProcess(base, "PROM0");
    ManualCondition prom0Condition = prom0.conditions.get(ManualCondition.class);
    PromotionProcess prom1 = createPromotionProcess(base, "PROM1");
    ManualCondition prom1Condition = prom1.conditions.get(ManualCondition.class);
    PromotionProcess prom2 = createPromotionProcess(base, "PROM2");
    ManualCondition prom2Condition = prom2.conditions.get(ManualCondition.class);
    FreeStyleBuild b1 = assertBuildStatusSuccess(p.scheduleBuild2(0));
    Promotion p0b1 = assertBuildStatusSuccess(prom0Condition.approve(b1, prom0));
    assertEquals(2, p0b1.getParameterValues().size());
    assertEquals(2, p0b1.getParameterDefinitionsWithValue().size());
    Promotion p1b1 = assertBuildStatusSuccess(prom1Condition.approve(b1, prom1));
    assertEquals(2, p1b1.getParameterValues().size());
    assertEquals(2, p1b1.getParameterDefinitionsWithValue().size());
    Promotion p2b1 = assertBuildStatusSuccess(prom2Condition.approve(b1, prom2));
    assertEquals(2, p2b1.getParameterValues().size());
    assertEquals(2, p2b1.getParameterDefinitionsWithValue().size());
    List<ManualApproval> approvals = b1.getActions(ManualApproval.class);
    assertEquals(3, approvals.size());
    PromotedBuildAction promBuildAction = b1.getAction(PromotedBuildAction.class);
    List<Status> statuses = promBuildAction.getPromotions();
    assertEquals(3, statuses.size());
    for (Status status : statuses) {
        Promotion lastBuild = status.getLast();
        List<ParameterDefinition> lastBuildParameters = lastBuild.getParameterDefinitionsWithValue();
        assertEquals(2, lastBuildParameters.size());
    }
}
Also used : Status(hudson.plugins.promoted_builds.Status) ManualApproval(hudson.plugins.promoted_builds.conditions.ManualCondition.ManualApproval) 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) PromotionProcess(hudson.plugins.promoted_builds.PromotionProcess) Descriptor(hudson.model.Descriptor) StringParameterDefinition(hudson.model.StringParameterDefinition) ParameterDefinition(hudson.model.ParameterDefinition)

Example 17 with FreeStyleBuild

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

the class ManualConditionBug22005 method testPromotionProcessViaWebClient.

public void testPromotionProcessViaWebClient() throws Exception {
    FreeStyleProject p = createFreeStyleProject();
    ExtensionList<Descriptor> list = hudson.getExtensionList(Descriptor.class);
    list.add(new JobPropertyImpl.DescriptorImpl(JobPropertyImpl.class));
    JobPropertyImpl base = new JobPropertyImpl(p);
    p.addProperty(base);
    createPromotionProcess(base, "PROM0");
    createPromotionProcess(base, "PROM1");
    createPromotionProcess(base, "PROM2");
    FreeStyleBuild b1 = assertBuildStatusSuccess(p.scheduleBuild2(0));
    assertNull(b1.getAction(ManualApproval.class));
    HtmlPage page = createWebClient().getPage(b1, "promotion");
    //Approve Promotion
    List<HtmlForm> forms = ManualConditionTest.getFormsByName(page, "approve");
    assertFalse(forms.isEmpty());
    assertEquals(3, forms.size());
    for (HtmlForm form : forms) {
        submit(form);
    }
    //reload promotions page
    page = createWebClient().getPage(b1, "promotion");
    forms = ManualConditionTest.getFormsByName(page, "build");
    for (HtmlForm form : forms) {
        List<HtmlElement> parameters = ManualConditionTest.getFormParameters(form);
        assertEquals(2, parameters.size());
    }
}
Also used : ManualApproval(hudson.plugins.promoted_builds.conditions.ManualCondition.ManualApproval) HtmlForm(com.gargoylesoftware.htmlunit.html.HtmlForm) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) HtmlElement(com.gargoylesoftware.htmlunit.html.HtmlElement) Descriptor(hudson.model.Descriptor) FreeStyleBuild(hudson.model.FreeStyleBuild) FreeStyleProject(hudson.model.FreeStyleProject) JobPropertyImpl(hudson.plugins.promoted_builds.JobPropertyImpl)

Example 18 with FreeStyleBuild

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

the class ManualConditionTest method testManualPromotionProcess.

public void testManualPromotionProcess() throws Exception {
    FreeStyleProject p = createFreeStyleProject();
    ExtensionList<Descriptor> list = hudson.getExtensionList(Descriptor.class);
    list.add(new JobPropertyImpl.DescriptorImpl(JobPropertyImpl.class));
    JobPropertyImpl base = new JobPropertyImpl(p);
    p.addProperty(base);
    PromotionProcess foo = base.addProcess("foo");
    ManualCondition condition = new ManualCondition();
    condition.getParameterDefinitions().add(new StringParameterDefinition("bogus_string_param_1", "bogus_value_1", "Bog parameter"));
    condition.getParameterDefinitions().add(new StringParameterDefinition("bogus_string_param_2", "bogus_value_2", "Bog parameter"));
    foo.conditions.add(condition);
    FreeStyleBuild b1 = assertBuildStatusSuccess(p.scheduleBuild2(0));
    // promote a build
    List<ParameterValue> paramValues = condition.createDefaultValues();
    //try to add duplicate values
    paramValues.addAll(condition.createDefaultValues());
    assertBuildStatusSuccess(condition.approve(b1, foo, paramValues));
    ManualApproval manualApproval = b1.getAction(ManualApproval.class);
    assertNotNull(manualApproval);
    PromotedBuildAction statuses = b1.getAction(PromotedBuildAction.class);
    assertNotNull(statuses);
    assertNotNull(statuses.getPromotions());
    assertFalse(statuses.getPromotions().isEmpty());
}
Also used : ManualApproval(hudson.plugins.promoted_builds.conditions.ManualCondition.ManualApproval) StringParameterDefinition(hudson.model.StringParameterDefinition) StringParameterValue(hudson.model.StringParameterValue) ParameterValue(hudson.model.ParameterValue) FreeStyleBuild(hudson.model.FreeStyleBuild) PromotedBuildAction(hudson.plugins.promoted_builds.PromotedBuildAction) FreeStyleProject(hudson.model.FreeStyleProject) JobPropertyImpl(hudson.plugins.promoted_builds.JobPropertyImpl) ManualCondition(hudson.plugins.promoted_builds.conditions.ManualCondition) DescriptorImpl(hudson.plugins.promoted_builds.JobPropertyImpl.DescriptorImpl) PromotionProcess(hudson.plugins.promoted_builds.PromotionProcess) Descriptor(hudson.model.Descriptor)

Example 19 with FreeStyleBuild

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

the class SelfPromotionTest method testUnstable.

public void testUnstable() 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(unstableBuilder());
    FreeStyleBuild b = assertBuildStatus(Result.UNSTABLE, 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 only one promotions happened
    assertTrue(promo1.getBuilds().isEmpty());
    Promotion pb = promo2.getBuilds().get(0);
    assertSame(pb.getTarget(), b);
    PromotedBuildAction badge = (PromotedBuildAction) b.getBadgeActions().get(0);
    assertFalse(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 20 with FreeStyleBuild

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

the class KeepBuildForeverActionTest method testDoesNotCareAboutResultOfOriginalBuild.

public void testDoesNotCareAboutResultOfOriginalBuild() throws Exception {
    FreeStyleProject upJob = createProject("up");
    upJob.getBuildersList().add(new FixedResultBuilder(Result.FAILURE));
    FreeStyleProject downJob = createProject("down");
    downJob.getBuildersList().add(successfulBuilder());
    PromotionProcess promotionJob = createDownstreamSuccessPromotion(upJob, downJob);
    promotionJob.getBuildSteps().add(new KeepBuildForeverAction());
    // fire ItemListeners, this includes ArtifactArchiver,Migrator to make this test compatible with jenkins 1.575+
    fireItemListeners();
    FreeStyleBuild upBuild = assertBuildStatus(Result.FAILURE, upJob.scheduleBuild2(0).get());
    assertFalse(upBuild.isKeepLog());
    assertBuildStatusSuccess(downJob.scheduleBuild2(0).get());
    waitForBuild(promotionJob, 1);
    assertTrue(upBuild.isKeepLog());
}
Also used : FreeStyleBuild(hudson.model.FreeStyleBuild) FreeStyleProject(hudson.model.FreeStyleProject)

Aggregations

FreeStyleBuild (hudson.model.FreeStyleBuild)42 FreeStyleProject (hudson.model.FreeStyleProject)42 Test (org.junit.Test)25 JobPropertyImpl (hudson.plugins.promoted_builds.JobPropertyImpl)14 PromotionProcess (hudson.plugins.promoted_builds.PromotionProcess)13 Shell (hudson.tasks.Shell)13 Map (java.util.Map)12 ImmutableMap (com.google.common.collect.ImmutableMap)11 PromotedBuildAction (hudson.plugins.promoted_builds.PromotedBuildAction)8 Promotion (hudson.plugins.promoted_builds.Promotion)7 StringParameterDefinition (hudson.model.StringParameterDefinition)6 ManualCondition (hudson.plugins.promoted_builds.conditions.ManualCondition)6 ManualApproval (hudson.plugins.promoted_builds.conditions.ManualCondition.ManualApproval)6 Descriptor (hudson.model.Descriptor)5 ParameterValue (hudson.model.ParameterValue)5 StringParameterValue (hudson.model.StringParameterValue)4 MockFolder (org.jvnet.hudson.test.MockFolder)4 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)3 Project (hudson.model.Project)3 DescriptorImpl (hudson.plugins.promoted_builds.JobPropertyImpl.DescriptorImpl)3