Search in sources :

Example 1 with BatchFile

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

the class PromotionBuildWrapperTest method testApplyBuildWrapper.

@Test
public void testApplyBuildWrapper() throws Exception {
    FreeStyleProject project = j.createFreeStyleProject();
    JobPropertyImpl jobProperty = new JobPropertyImpl(project);
    project.addProperty(jobProperty);
    PromotionProcess promotion = jobProperty.addProcess("test");
    TestBuildWrapper buildWrapper = new TestBuildWrapper();
    promotion.getBuildWrappersList().add(buildWrapper);
    promotion.getBuildSteps().add(Functions.isWindows() ? new BatchFile("echo Hello, world") : new Shell("echo Hello, world"));
    // trigger build
    FreeStyleBuild build = j.assertBuildStatusSuccess(project.scheduleBuild2(0).get());
    // trigger promotion
    promotion.promote(build, new Cause.UserIdCause(), new ManualPromotionBadge());
    Thread.sleep(1000);
    assertEquals(1, promotion.getBuilds().size());
    Promotion promotionBuild = promotion.getBuilds().get(0);
    assertSame(promotionBuild.getTargetBuildOrFail(), build);
    assertEquals(Result.SUCCESS, buildWrapper.buildResultInTearDown);
}
Also used : TestBuildWrapper(org.jvnet.hudson.test.JenkinsRule.TestBuildWrapper) BatchFile(hudson.tasks.BatchFile) Shell(hudson.tasks.Shell) Cause(hudson.model.Cause) FreeStyleBuild(hudson.model.FreeStyleBuild) FreeStyleProject(hudson.model.FreeStyleProject) Test(org.junit.Test)

Example 2 with BatchFile

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

the class PromotionTest method testPromotionLog.

@Test
@Issue("JENKINS-59600")
public void testPromotionLog() throws Exception {
    FreeStyleProject p = r.createFreeStyleProject("proj1");
    JobPropertyImpl promotion = new JobPropertyImpl(p);
    p.addProperty(promotion);
    PromotionProcess promo1 = promotion.addProcess("promo1");
    promo1.getBuildSteps().add(Functions.isWindows() ? new BatchFile("echo ABCDEFGH") : new Shell("echo ABCDEFGH"));
    promo1.conditions.add(new SelfPromotionCondition(false));
    FreeStyleBuild b = r.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);
    Promotion pb = promo1.getBuilds().getLastBuild();
    assertSame(pb.getTargetBuildOrFail(), b);
    JenkinsRule.WebClient wc = r.createWebClient();
    // spot-check that promotion itself is accessible
    final Page page = wc.goTo(pb.getUrl() + "consoleText", "text/plain");
    assertThat(pb.getUrl() + "/consoleText + is not a promotion log", page.getWebResponse().getContentAsString(), CoreMatchers.containsString("ABCDEFGH"));
}
Also used : BatchFile(hudson.tasks.BatchFile) Shell(hudson.tasks.Shell) SelfPromotionCondition(hudson.plugins.promoted_builds.conditions.SelfPromotionCondition) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) Page(com.gargoylesoftware.htmlunit.Page) FreeStyleBuild(hudson.model.FreeStyleBuild) JenkinsRule(org.jvnet.hudson.test.JenkinsRule) FreeStyleProject(hudson.model.FreeStyleProject) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test)

Example 3 with BatchFile

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

the class PromotionProcessTest method test1.

@Test
public void test1() throws Exception {
    FreeStyleProject up = j.createFreeStyleProject("up");
    FreeStyleProject down = j.createFreeStyleProject();
    Recorder r1 = new ArtifactArchiver("a.jar", null, false);
    Recorder r2 = new Fingerprinter("", true);
    List<Recorder> recorders = Arrays.asList(r1, r2);
    // upstream job
    up.getBuildersList().add(Functions.isWindows() ? new BatchFile("date /t > a.jar") : 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 = j.createWebClient().getContextPath() + "job/up/lastSuccessfulBuild";
    String artifactUrl = baseUrl + "/artifact/a.jar";
    down.getBuildersList().add(Functions.isWindows() ? new BatchFile("powershell -command \"Invoke-WebRequest " + artifactUrl + " -OutFile a.jar\"\r\n" + "set /a \"exitCode=BUILD_NUMBER%%2\"\r\n" + "exit /b %exitCode%\r\n") : new Shell("wget -N " + artifactUrl + " \\\n" + "  || curl " + artifactUrl + " > 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 = j.assertBuildStatusSuccess(up.scheduleBuild2(0).get());
    j.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
    j.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.getTargetBuildOrFail(), up1);
        PromotedBuildAction badge = (PromotedBuildAction) up1.getBadgeActions().get(0);
        assertTrue(badge.contains(proc));
    }
    // make sure the UI persists the setup
    j.configRoundtrip(up);
}
Also used : BatchFile(hudson.tasks.BatchFile) 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) Test(org.junit.Test)

Example 4 with BatchFile

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

the class PromotionProcessTest method testPromotionWithoutFingerprint.

/**
 * Tests a promotion induced by the pseudo upstream/downstream cause relationship
 */
@Test
public void testPromotionWithoutFingerprint() throws Exception {
    FreeStyleProject up = j.createFreeStyleProject("up");
    FreeStyleProject down = j.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));
    j.jenkins.rebuildDependencyGraph();
    // this is the downstream job
    down.getBuildersList().add(Functions.isWindows() ? new BatchFile("set /a \"exitCode=BUILD_NUMBER%%2\"\r\n" + "exit /b %exitCode%\r\n") : // expr exits with non-zero status if result is zero
    new Shell("expr $BUILD_NUMBER % 2 - 1\n"));
    // not yet promoted while the downstream is failing
    FreeStyleBuild up1 = j.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 = j.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.getTargetBuildOrFail(), up2);
        PromotedBuildAction badge = (PromotedBuildAction) up2.getBadgeActions().get(0);
        assertTrue(badge.contains(proc));
    }
}
Also used : BatchFile(hudson.tasks.BatchFile) Shell(hudson.tasks.Shell) DownstreamPassCondition(hudson.plugins.promoted_builds.conditions.DownstreamPassCondition) BuildTrigger(hudson.tasks.BuildTrigger) FreeStyleBuild(hudson.model.FreeStyleBuild) FreeStyleProject(hudson.model.FreeStyleProject) Test(org.junit.Test)

Aggregations

FreeStyleBuild (hudson.model.FreeStyleBuild)4 FreeStyleProject (hudson.model.FreeStyleProject)4 BatchFile (hudson.tasks.BatchFile)4 Shell (hudson.tasks.Shell)4 Test (org.junit.Test)4 DownstreamPassCondition (hudson.plugins.promoted_builds.conditions.DownstreamPassCondition)2 Page (com.gargoylesoftware.htmlunit.Page)1 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)1 Cause (hudson.model.Cause)1 SelfPromotionCondition (hudson.plugins.promoted_builds.conditions.SelfPromotionCondition)1 ArtifactArchiver (hudson.tasks.ArtifactArchiver)1 BuildTrigger (hudson.tasks.BuildTrigger)1 Fingerprinter (hudson.tasks.Fingerprinter)1 Recorder (hudson.tasks.Recorder)1 Issue (org.jvnet.hudson.test.Issue)1 JenkinsRule (org.jvnet.hudson.test.JenkinsRule)1 TestBuildWrapper (org.jvnet.hudson.test.JenkinsRule.TestBuildWrapper)1