Search in sources :

Example 1 with Fingerprinter

use of hudson.tasks.Fingerprinter in project promoted-builds-plugin by jenkinsci.

the class PromotionProcessTest method test1.

public void test1() throws Exception {
    FreeStyleProject up = createFreeStyleProject("up");
    FreeStyleProject down = createFreeStyleProject();
    List<Recorder> recorders = Arrays.asList(new ArtifactArchiver("a.jar", null, false), new Fingerprinter("", true));
    // upstream job
    up.getBuildersList().add(new Shell("date > a.jar"));
    up.getPublishersList().replaceBy(recorders);
    // 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()));
    // this is the test job
    String baseUrl = new WebClient().getContextPath() + "job/up/lastSuccessfulBuild";
    down.getBuildersList().add(new Shell("wget -N " + baseUrl + "/artifact/a.jar \\\n" + "  || curl " + baseUrl + "/artifact/a.jar > a.jar\n" + // expr exits with non-zero status if result is zero
    "expr $BUILD_NUMBER % 2 - 1\n"));
    down.getPublishersList().replaceBy(recorders);
    // fire ItemListeners, this includes ArtifactArchiver,Migrator to make this test compatible with jenkins 1.575+
    fireItemListeners();
    // not yet promoted while the downstream is failing
    FreeStyleBuild up1 = assertBuildStatusSuccess(up.scheduleBuild2(0).get());
    assertBuildStatus(Result.FAILURE, down.scheduleBuild2(0).get());
    // give it a time to not promote
    Thread.sleep(1000);
    assertEquals(0, proc.getBuilds().size());
    // a successful downstream build promotes upstream
    assertBuildStatusSuccess(down.scheduleBuild2(0).get());
    // give it a time to promote
    Thread.sleep(1000);
    assertEquals(1, proc.getBuilds().size());
    {
        // verify that it promoted the right stuff
        Promotion pb = proc.getBuilds().get(0);
        assertSame(pb.getTarget(), up1);
        PromotedBuildAction badge = (PromotedBuildAction) up1.getBadgeActions().get(0);
        assertTrue(badge.contains(proc));
    }
    // make sure the UI persists the setup
    configRoundtrip(up);
}
Also used : ArtifactArchiver(hudson.tasks.ArtifactArchiver) DownstreamPassCondition(hudson.plugins.promoted_builds.conditions.DownstreamPassCondition) Recorder(hudson.tasks.Recorder) FreeStyleBuild(hudson.model.FreeStyleBuild) FreeStyleProject(hudson.model.FreeStyleProject) Shell(hudson.tasks.Shell) Fingerprinter(hudson.tasks.Fingerprinter)

Aggregations

FreeStyleBuild (hudson.model.FreeStyleBuild)1 FreeStyleProject (hudson.model.FreeStyleProject)1 DownstreamPassCondition (hudson.plugins.promoted_builds.conditions.DownstreamPassCondition)1 ArtifactArchiver (hudson.tasks.ArtifactArchiver)1 Fingerprinter (hudson.tasks.Fingerprinter)1 Recorder (hudson.tasks.Recorder)1 Shell (hudson.tasks.Shell)1