Search in sources :

Example 31 with FreeStyleBuild

use of hudson.model.FreeStyleBuild 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 32 with FreeStyleBuild

use of hudson.model.FreeStyleBuild 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 33 with FreeStyleBuild

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

the class PromotionProcessTest method testPromotionWithoutFingerprint.

/**
     * Tests a promotion induced by the pseudo upstream/downstream cause relationship
     */
public void testPromotionWithoutFingerprint() throws Exception {
    FreeStyleProject up = createFreeStyleProject("up");
    FreeStyleProject down = createFreeStyleProject();
    // promote if the downstream passes
    JobPropertyImpl promotion = new JobPropertyImpl(up);
    up.addProperty(promotion);
    PromotionProcess proc = promotion.addProcess("promo");
    proc.conditions.add(new DownstreamPassCondition(down.getName()));
    // trigger downstream automatically to create relationship
    up.getPublishersList().add(new BuildTrigger(down.getName(), Result.SUCCESS));
    hudson.rebuildDependencyGraph();
    // this is the downstream job
    down.getBuildersList().add(new Shell(// expr exits with non-zero status if result is zero
    "expr $BUILD_NUMBER % 2 - 1\n"));
    // not yet promoted while the downstream is failing
    FreeStyleBuild up1 = assertBuildStatusSuccess(up.scheduleBuild2(0).get());
    waitForCompletion(down, 1);
    assertEquals(0, proc.getBuilds().size());
    // do it one more time and this time it should work
    FreeStyleBuild up2 = assertBuildStatusSuccess(up.scheduleBuild2(0).get());
    waitForCompletion(down, 2);
    assertEquals(1, proc.getBuilds().size());
    {
        // verify that it promoted the right stuff
        Promotion pb = proc.getBuilds().get(0);
        assertSame(pb.getTarget(), up2);
        PromotedBuildAction badge = (PromotedBuildAction) up2.getBadgeActions().get(0);
        assertTrue(badge.contains(proc));
    }
}
Also used : Shell(hudson.tasks.Shell) DownstreamPassCondition(hudson.plugins.promoted_builds.conditions.DownstreamPassCondition) BuildTrigger(hudson.tasks.BuildTrigger) FreeStyleBuild(hudson.model.FreeStyleBuild) FreeStyleProject(hudson.model.FreeStyleProject)

Example 34 with FreeStyleBuild

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

the class PromotionTargetActionTest method test1.

/**
     * When a project is created, built, and renamed, then the old build is created,
     * that results in NPE.
     */
public void test1() throws Exception {
    FreeStyleProject up = createFreeStyleProject("up");
    up.setCustomWorkspace(createTmpDir().getPath());
    // promote if the downstream passes
    JobPropertyImpl promotion = new JobPropertyImpl(up);
    up.addProperty(promotion);
    PromotionProcess proc = promotion.addProcess("promo");
    proc.conditions.add(new ManualCondition());
    FreeStyleBuild b = assertBuildStatusSuccess(up.scheduleBuild2(0));
    b.addAction(new ManualApproval(proc.getName(), Collections.<ParameterValue>emptyList()));
    b.save();
    // check for promotion
    Promotion p = assertBuildStatusSuccess(proc.considerPromotion2(b));
    up.renameTo("up2");
    assertSame(b, p.getTarget());
}
Also used : ManualCondition(hudson.plugins.promoted_builds.conditions.ManualCondition) ManualApproval(hudson.plugins.promoted_builds.conditions.ManualCondition.ManualApproval) ParameterValue(hudson.model.ParameterValue) FreeStyleBuild(hudson.model.FreeStyleBuild) FreeStyleProject(hudson.model.FreeStyleProject)

Example 35 with FreeStyleBuild

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

the class LastBuildPromotionStatusColumnTest method shouldDisplayStars.

@Test
public void shouldDisplayStars() throws Exception {
    // Create project
    FreeStyleProject p = j.createFreeStyleProject();
    JobPropertyImpl base = new JobPropertyImpl(p);
    p.addProperty(base);
    PromotionProcess foo = base.addProcess("foo");
    foo.icon = "star-blue";
    view.add(p);
    // Promote a build
    FreeStyleBuild b1 = j.assertBuildStatusSuccess(p.scheduleBuild2(0));
    foo.promote(b1, new Cause.UserIdCause(), new ManualPromotionBadge());
    // Check column contents
    LastBuildPromotionStatusColumn retrieved = view.getColumns().get(LastBuildPromotionStatusColumn.class);
    assertEquals("Columns should be same", column, retrieved);
    List<String> promotionIcons = retrieved.getPromotionIcons(p);
    assertEquals("Expected only 1 promotion icon", 1, promotionIcons.size());
    assertTrue("Promotion should assign the blue star", promotionIcons.get(0).contains("star-blue"));
}
Also used : Cause(hudson.model.Cause) FreeStyleBuild(hudson.model.FreeStyleBuild) FreeStyleProject(hudson.model.FreeStyleProject) Test(org.junit.Test)

Aggregations

FreeStyleBuild (hudson.model.FreeStyleBuild)45 FreeStyleProject (hudson.model.FreeStyleProject)45 Test (org.junit.Test)28 Shell (hudson.tasks.Shell)15 JobPropertyImpl (hudson.plugins.promoted_builds.JobPropertyImpl)14 PromotionProcess (hudson.plugins.promoted_builds.PromotionProcess)13 Map (java.util.Map)13 ImmutableMap (com.google.common.collect.ImmutableMap)12 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 MockFolder (org.jvnet.hudson.test.MockFolder)5 StringParameterValue (hudson.model.StringParameterValue)4 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)3 Project (hudson.model.Project)3 DescriptorImpl (hudson.plugins.promoted_builds.JobPropertyImpl.DescriptorImpl)3