Search in sources :

Example 1 with DownstreamPassCondition

use of hudson.plugins.promoted_builds.conditions.DownstreamPassCondition in project promoted-builds-plugin by jenkinsci.

the class DownstreamPassConditionInheritanceTest method shouldEvaluateUpstreamRecursively.

@Test
@Issue("JENKINS-7739")
public void shouldEvaluateUpstreamRecursively() throws Exception {
    final InheritanceProjectsPair pair1 = j.createInheritanceProjectDerivedWithBase();
    final InheritanceProjectsPair pair2 = j.createInheritanceProjectDerivedWithBase();
    final InheritanceProjectsPair pair3 = j.createInheritanceProjectDerivedWithBase();
    final JobPropertyImpl property = new JobPropertyImpl(pair1.getBase());
    pair1.getBase().addProperty(property);
    final PromotionProcess process = property.addProcess("promotion");
    process.conditions.add(new DownstreamPassCondition(pair3.getDerived().getFullName()));
    pair1.getDerived().getPublishersList().add(new BuildTrigger(pair2.getDerived().getFullName(), Result.SUCCESS));
    pair2.getDerived().getPublishersList().add(new BuildTrigger(pair3.getDerived().getFullName(), Result.SUCCESS));
    j.jenkins.rebuildDependencyGraph();
    final InheritanceBuild run1 = j.buildAndAssertSuccess(pair1.getDerived());
    j.assertBuildStatusSuccess(run1);
    j.waitUntilNoActivity();
    j.assertBuildStatusSuccess(pair2.getDerived().getLastBuild());
    j.waitUntilNoActivity();
    final InheritanceBuild run3 = j.assertBuildStatusSuccess(pair3.getDerived().getLastBuild());
    j.waitUntilNoActivity();
    // We cannot assume that the process will contain builds because the process added to base project is different to the one in derived.
    JobPropertyImpl jobProperty = pair1.getDerived().getProperty(JobPropertyImpl.class, /*Forcing inheritance as temporary hack for inheritance plugin 1.53 
                because that version of the plugin uses inheritance only for certain predefined cases: 
                -specific methods on the call stack
                -url paths.
                This has been changed as pull request https://github.com/i-m-c/jenkins-inheritance-plugin/pull/40
               */
    IMode.INHERIT_FORCED);
    assertNotNull("derived jobProperty is null", jobProperty);
    PromotionProcess processDerived = jobProperty.getItem("promotion");
    assertEquals("fingerprint relation", run3.getUpstreamRelationship(pair1.getDerived()), -1);
    assertFalse("no promotion process", processDerived.getBuilds().isEmpty());
    final PromotedBuildAction action = run1.getAction(PromotedBuildAction.class);
    assertNotNull("no promoted action", action);
    final Status promotion = action.getPromotion("promotion");
    assertNotNull("promotion not found", promotion);
    assertTrue("promotion not successful", promotion.isPromotionSuccessful());
}
Also used : InheritanceProjectsPair(hudson.plugins.promoted_builds.inheritance.helpers.InheritanceProjectsPair) Status(hudson.plugins.promoted_builds.Status) InheritanceBuild(hudson.plugins.project_inheritance.projects.InheritanceBuild) DownstreamPassCondition(hudson.plugins.promoted_builds.conditions.DownstreamPassCondition) PromotionProcess(hudson.plugins.promoted_builds.PromotionProcess) BuildTrigger(hudson.tasks.BuildTrigger) PromotedBuildAction(hudson.plugins.promoted_builds.PromotedBuildAction) JobPropertyImpl(hudson.plugins.promoted_builds.JobPropertyImpl) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test)

Example 2 with DownstreamPassCondition

use of hudson.plugins.promoted_builds.conditions.DownstreamPassCondition in project promoted-builds-plugin by jenkinsci.

the class ConfigurationRoundtripTest method testRoundtrip.

/**
 * Configuration roundtrip test to detect data loss.
 */
@Test
public void testRoundtrip() throws Exception {
    FreeStyleProject down = j.createFreeStyleProject();
    FreeStyleProject p = j.createFreeStyleProject();
    JobPropertyImpl pp = new JobPropertyImpl(p);
    p.addProperty(pp);
    PromotionProcess proc = pp.addProcess("test");
    assertEquals(1, pp.getItems().size());
    proc.conditions.add(new DownstreamPassCondition(down.getName()));
    proc.getBuildSteps().add(new JavadocArchiver("somedir", true));
    proc.getBuildWrappersList().add(new ConfigFileBuildWrapper(new ArrayList<ManagedFile>()));
    proc.icon = "star-blue";
    // round trip
    JenkinsRule.WebClient wc = j.createWebClient();
    submit(wc.getPage(p, "configure").getFormByName("config"));
    // assert that the configuration is still intact
    pp = p.getProperty(JobPropertyImpl.class);
    assertEquals(1, pp.getItems().size());
    proc = pp.getItem("test");
    assertEquals(1, proc.conditions.toList().size());
    DownstreamPassCondition dcp = proc.conditions.get(DownstreamPassCondition.class);
    assertEquals(dcp.getJobs(), down.getName());
    assertEquals(1, proc.getBuildSteps().size());
    JavadocArchiver ja = (JavadocArchiver) proc.getBuildSteps().get(0);
    assertEquals("somedir", ja.getJavadocDir());
    assertTrue(ja.isKeepAll());
    ConfigFileBuildWrapper buildWrapper = (ConfigFileBuildWrapper) proc.getBuildWrappersList().get(0);
    assertNotNull(buildWrapper);
    assertEquals("star-blue", proc.icon);
}
Also used : DownstreamPassCondition(hudson.plugins.promoted_builds.conditions.DownstreamPassCondition) ArrayList(java.util.ArrayList) ConfigFileBuildWrapper(org.jenkinsci.plugins.configfiles.buildwrapper.ConfigFileBuildWrapper) JavadocArchiver(hudson.tasks.JavadocArchiver) JenkinsRule(org.jvnet.hudson.test.JenkinsRule) FreeStyleProject(hudson.model.FreeStyleProject) Test(org.junit.Test)

Example 3 with DownstreamPassCondition

use of hudson.plugins.promoted_builds.conditions.DownstreamPassCondition 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 DownstreamPassCondition

use of hudson.plugins.promoted_builds.conditions.DownstreamPassCondition in project promoted-builds-plugin by jenkinsci.

the class ConfigurationDoCheckTest method testCheckInvalidProcessName.

@Issue("JENKINS-7972")
@Test
public void testCheckInvalidProcessName() throws Exception {
    FreeStyleProject down = j.createFreeStyleProject();
    FreeStyleProject p = j.createFreeStyleProject();
    JobPropertyImpl pp = new JobPropertyImpl(p);
    p.addProperty(pp);
    PromotionProcess proc = pp.addProcess("test/");
    assertEquals(1, pp.getItems().size());
    proc.conditions.add(new DownstreamPassCondition(down.getName()));
    proc.getBuildSteps().add(new JavadocArchiver("somedir", true));
    proc.icon = "star-blue";
    JenkinsRule.WebClient client = j.createWebClient();
    client.getOptions().setThrowExceptionOnFailingStatusCode(false);
    HtmlPage page = (HtmlPage) submit(client.getPage(p, "configure").getFormByName("config"));
    assertTrue(page.getVisibleText().contains("unsafe character"));
}
Also used : DownstreamPassCondition(hudson.plugins.promoted_builds.conditions.DownstreamPassCondition) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) JavadocArchiver(hudson.tasks.JavadocArchiver) JenkinsRule(org.jvnet.hudson.test.JenkinsRule) FreeStyleProject(hudson.model.FreeStyleProject) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test)

Example 5 with DownstreamPassCondition

use of hudson.plugins.promoted_builds.conditions.DownstreamPassCondition in project promoted-builds-plugin by jenkinsci.

the class ConfigurationDoCheckTest method testCheckProcessNameRequired.

@Issue("JENKINS-7972")
@Test
public void testCheckProcessNameRequired() throws Exception {
    FreeStyleProject down = j.createFreeStyleProject();
    FreeStyleProject p = j.createFreeStyleProject();
    JobPropertyImpl pp = new JobPropertyImpl(p);
    p.addProperty(pp);
    PromotionProcess proc = pp.addProcess("");
    assertEquals(1, pp.getItems().size());
    proc.conditions.add(new DownstreamPassCondition(down.getName()));
    proc.getBuildSteps().add(new JavadocArchiver("somedir", true));
    proc.icon = "star-blue";
    JenkinsRule.WebClient client = j.createWebClient();
    client.getOptions().setThrowExceptionOnFailingStatusCode(false);
    HtmlPage page = (HtmlPage) submit(client.getPage(p, "configure").getFormByName("config"));
    assertTrue(page.getVisibleText().contains("No name is specified"));
}
Also used : DownstreamPassCondition(hudson.plugins.promoted_builds.conditions.DownstreamPassCondition) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) JavadocArchiver(hudson.tasks.JavadocArchiver) JenkinsRule(org.jvnet.hudson.test.JenkinsRule) FreeStyleProject(hudson.model.FreeStyleProject) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test)

Aggregations

DownstreamPassCondition (hudson.plugins.promoted_builds.conditions.DownstreamPassCondition)8 Test (org.junit.Test)6 FreeStyleProject (hudson.model.FreeStyleProject)5 JavadocArchiver (hudson.tasks.JavadocArchiver)3 Issue (org.jvnet.hudson.test.Issue)3 JenkinsRule (org.jvnet.hudson.test.JenkinsRule)3 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)2 FreeStyleBuild (hudson.model.FreeStyleBuild)2 BatchFile (hudson.tasks.BatchFile)2 BuildTrigger (hudson.tasks.BuildTrigger)2 Shell (hudson.tasks.Shell)2 InheritanceBuild (hudson.plugins.project_inheritance.projects.InheritanceBuild)1 JobPropertyImpl (hudson.plugins.promoted_builds.JobPropertyImpl)1 PromotedBuildAction (hudson.plugins.promoted_builds.PromotedBuildAction)1 PromotionProcess (hudson.plugins.promoted_builds.PromotionProcess)1 Status (hudson.plugins.promoted_builds.Status)1 ParameterizedSelfPromotionCondition (hudson.plugins.promoted_builds.conditions.ParameterizedSelfPromotionCondition)1 SelfPromotionCondition (hudson.plugins.promoted_builds.conditions.SelfPromotionCondition)1 UpstreamPromotionCondition (hudson.plugins.promoted_builds.conditions.UpstreamPromotionCondition)1 InheritanceProjectsPair (hudson.plugins.promoted_builds.inheritance.helpers.InheritanceProjectsPair)1