Search in sources :

Example 26 with FreeStyleProject

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

the class PromotionProcessTest method testIsVisibleByDefault.

public void testIsVisibleByDefault() throws Exception {
    FreeStyleProject project = createFreeStyleProject("project");
    JobPropertyImpl jobProperty = new JobPropertyImpl(project);
    project.addProperty(jobProperty);
    PromotionProcess promotionProcess = jobProperty.addProcess("Promotion");
    assertTrue(promotionProcess.isVisible());
}
Also used : FreeStyleProject(hudson.model.FreeStyleProject)

Example 27 with FreeStyleProject

use of hudson.model.FreeStyleProject 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)

Example 28 with FreeStyleProject

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

the class RemoteApiTest method create.

@Test
public void create() throws Exception {
    FreeStyleProject p = r.createFreeStyleProject("p");
    JobPropertyImpl promotion = new JobPropertyImpl(p);
    p.addProperty(promotion);
    assertEquals(0, promotion.getItems().size());
    assertEquals(0, promotion.getActiveItems().size());
    JenkinsRule.WebClient wc = r.createWebClient();
    WebRequest req = new WebRequest(new URL(wc.createCrumbedUrl("job/p/promotion/createProcess") + "&name=promo"), HttpMethod.POST);
    req.setEncodingType(null);
    req.setRequestBody("<hudson.plugins.promoted__builds.PromotionProcess><conditions><hudson.plugins.promoted__builds.conditions.SelfPromotionCondition><evenIfUnstable>true</evenIfUnstable></hudson.plugins.promoted__builds.conditions.SelfPromotionCondition></conditions></hudson.plugins.promoted__builds.PromotionProcess>");
    wc.getPage(req);
    assertEquals(1, promotion.getItems().size());
    assertEquals("not yet in use", 0, promotion.getActiveItems().size());
    PromotionProcess proc = promotion.getItem("promo");
    assertNotNull(proc);
    assertTrue(proc.conditions.get(SelfPromotionCondition.class).isEvenIfUnstable());
}
Also used : WebRequest(com.gargoylesoftware.htmlunit.WebRequest) JenkinsRule(org.jvnet.hudson.test.JenkinsRule) FreeStyleProject(hudson.model.FreeStyleProject) URL(java.net.URL) Test(org.junit.Test)

Example 29 with FreeStyleProject

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

the class RemoteApiTest method getAndModify.

@Test
public void getAndModify() throws Exception {
    FreeStyleProject p = r.createFreeStyleProject("p");
    JobPropertyImpl promotion = new JobPropertyImpl(p);
    p.addProperty(promotion);
    PromotionProcess proc = promotion.addProcess("promo");
    proc.conditions.add(new SelfPromotionCondition(true));
    JenkinsRule.WebClient wc = r.createWebClient();
    String xml = wc.goToXml("job/p/promotion/process/promo/config.xml").getContent();
    assertTrue(xml, xml.contains("SelfPromotionCondition"));
    assertTrue(xml, xml.contains("<evenIfUnstable>true</evenIfUnstable>"));
    WebRequest req = new WebRequest(wc.createCrumbedUrl("job/p/promotion/process/promo/config.xml"), HttpMethod.POST);
    req.setEncodingType(null);
    req.setRequestBody(xml.replace("<evenIfUnstable>true</evenIfUnstable>", "<evenIfUnstable>false</evenIfUnstable>"));
    assertTrue(proc.conditions.get(SelfPromotionCondition.class).isEvenIfUnstable());
    wc.getPage(req);
    assertFalse(proc.conditions.get(SelfPromotionCondition.class).isEvenIfUnstable());
}
Also used : WebRequest(com.gargoylesoftware.htmlunit.WebRequest) SelfPromotionCondition(hudson.plugins.promoted_builds.conditions.SelfPromotionCondition) JenkinsRule(org.jvnet.hudson.test.JenkinsRule) FreeStyleProject(hudson.model.FreeStyleProject) Test(org.junit.Test)

Example 30 with FreeStyleProject

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

the class DownstreamPassConditionTest method shouldEvaluateUpstreamRecursively.

@Test
@Bug(7739)
public void shouldEvaluateUpstreamRecursively() throws Exception {
    final FreeStyleProject job1 = j.createFreeStyleProject("job1");
    final FreeStyleProject job2 = j.createFreeStyleProject("job2");
    final FreeStyleProject job3 = j.createFreeStyleProject("job3");
    final JobPropertyImpl property = new JobPropertyImpl(job1);
    job1.addProperty(property);
    final PromotionProcess process = property.addProcess("promotion");
    process.conditions.add(new DownstreamPassCondition(job3.getFullName()));
    job1.getPublishersList().add(new BuildTrigger(job2.getFullName(), Result.SUCCESS));
    job2.getPublishersList().add(new BuildTrigger(job3.getFullName(), Result.SUCCESS));
    j.jenkins.rebuildDependencyGraph();
    final FreeStyleBuild run1 = j.buildAndAssertSuccess(job1);
    j.waitUntilNoActivity();
    j.assertBuildStatusSuccess(job2.getLastBuild());
    j.waitUntilNoActivity();
    final FreeStyleBuild run3 = j.assertBuildStatusSuccess(job3.getLastBuild());
    j.waitUntilNoActivity();
    assertEquals("fingerprint relation", run3.getUpstreamRelationship(job1), -1);
    assertFalse("no promotion process", process.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 : Status(hudson.plugins.promoted_builds.Status) PromotionProcess(hudson.plugins.promoted_builds.PromotionProcess) BuildTrigger(hudson.tasks.BuildTrigger) FreeStyleBuild(hudson.model.FreeStyleBuild) PromotedBuildAction(hudson.plugins.promoted_builds.PromotedBuildAction) FreeStyleProject(hudson.model.FreeStyleProject) JobPropertyImpl(hudson.plugins.promoted_builds.JobPropertyImpl) Test(org.junit.Test) Bug(org.jvnet.hudson.test.Bug)

Aggregations

FreeStyleProject (hudson.model.FreeStyleProject)77 Test (org.junit.Test)49 FreeStyleBuild (hudson.model.FreeStyleBuild)39 Shell (hudson.tasks.Shell)17 Map (java.util.Map)16 JobPropertyImpl (hudson.plugins.promoted_builds.JobPropertyImpl)14 ImmutableMap (com.google.common.collect.ImmutableMap)13 PromotionProcess (hudson.plugins.promoted_builds.PromotionProcess)13 ArrayList (java.util.ArrayList)11 StringParameterDefinition (hudson.model.StringParameterDefinition)10 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)10 PromotedBuildAction (hudson.plugins.promoted_builds.PromotedBuildAction)8 FreeStyleProjectMock (hudson.model.FreeStyleProjectMock)7 Promotion (hudson.plugins.promoted_builds.Promotion)7 MockFolder (org.jvnet.hudson.test.MockFolder)7 ManualCondition (hudson.plugins.promoted_builds.conditions.ManualCondition)6 ManualApproval (hudson.plugins.promoted_builds.conditions.ManualCondition.ManualApproval)6 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)5 Descriptor (hudson.model.Descriptor)5 Hudson (hudson.model.Hudson)5