Search in sources :

Example 11 with FreeStyleBuild

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

the class PromotedBuildActionTest method testDeletedPromotionProcess.

public void testDeletedPromotionProcess() throws Exception {
    FreeStyleProject p = createFreeStyleProject();
    JobPropertyImpl base = new JobPropertyImpl(p);
    p.addProperty(base);
    PromotionProcess foo = base.addProcess("foo");
    // promote a build
    FreeStyleBuild b1 = assertBuildStatusSuccess(p.scheduleBuild2(0));
    foo.promote(b1, new UserCause(), new ManualPromotionBadge());
    // now delete the promotion process
    p.removeProperty(base);
    p.addProperty(base = new JobPropertyImpl(p));
    assertTrue(base.getActiveItems().isEmpty());
    // make sure that the page renders OK without any error
    HtmlPage page = createWebClient().getPage(p);
    List<?> candidates = page.getByXPath("//IMG");
    for (Object candidate : candidates) {
        if (!(candidate instanceof HtmlImage)) {
            continue;
        }
        HtmlImage img = (HtmlImage) candidate;
        try {
            img.getHeight();
        } catch (IOException e) {
            throw new IOException2("Failed to load " + img.getSrcAttribute(), e);
        }
    }
}
Also used : HtmlImage(com.gargoylesoftware.htmlunit.html.HtmlImage) UserCause(hudson.model.Cause.UserCause) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) FreeStyleBuild(hudson.model.FreeStyleBuild) IOException(java.io.IOException) FreeStyleProject(hudson.model.FreeStyleProject) IOException2(hudson.util.IOException2)

Example 12 with FreeStyleBuild

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

the class PromotionEnvironmentVariablesTest method shouldSetJobAndJobFullNames.

@Test
public void shouldSetJobAndJobFullNames() throws Descriptor.FormException, IOException, InterruptedException, ExecutionException, Exception {
    // Assemble
    r.jenkins.setSecurityRealm(r.createDummySecurityRealm());
    User u = User.get("foo");
    u.setFullName("Foobar");
    SecurityContextHolder.getContext().setAuthentication(u.impersonate());
    MockFolder parent = r.createFolder("Folder");
    FreeStyleProject project = parent.createProject(FreeStyleProject.class, "Project");
    JobPropertyImpl promotionProperty = new JobPropertyImpl(project);
    PromotionProcess promotionProcess = promotionProperty.addProcess("promo");
    promotionProcess.conditions.clear();
    promotionProcess.conditions.add(new ManualCondition());
    Action approvalAction = new ManualCondition.ManualApproval(promotionProcess.getName(), new ArrayList<ParameterValue>());
    // Act
    FreeStyleBuild build = project.scheduleBuild2(0).get();
    build.setDisplayName("1234");
    build.addAction(approvalAction);
    build.save();
    Promotion promotion = promotionProcess.considerPromotion2(build).get();
    EnvVars env = promotion.getEnvironment(TaskListener.NULL);
    // Assert
    assertEquals("Folder/Project", env.get("PROMOTED_JOB_FULL_NAME"));
    assertEquals("Project", env.get("PROMOTED_JOB_NAME"));
    assertEquals("Foobar", env.get("PROMOTED_USER_NAME"));
    assertEquals("foo", env.get("PROMOTED_USER_ID"));
    assertEquals("1234", env.get("PROMOTED_DISPLAY_NAME"));
    project.delete();
    parent.delete();
}
Also used : Action(hudson.model.Action) User(hudson.model.User) ParameterValue(hudson.model.ParameterValue) FreeStyleBuild(hudson.model.FreeStyleBuild) MockFolder(org.jvnet.hudson.test.MockFolder) FreeStyleProject(hudson.model.FreeStyleProject) ManualCondition(hudson.plugins.promoted_builds.conditions.ManualCondition) EnvVars(hudson.EnvVars) Test(org.junit.Test)

Example 13 with FreeStyleBuild

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

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

Example 15 with FreeStyleBuild

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

the class GroovyConditionTest method testBinding.

@Test
public void testBinding() throws Exception {
    FreeStyleProject p = j.createFreeStyleProject();
    final JobPropertyImpl property = new JobPropertyImpl(p);
    final PromotionProcess promotionProcess = property.addProcess("testPromotion");
    promotionProcess.conditions.add(new GroovyCondition(new SecureGroovyScript("promotionProcess instanceof hudson.plugins.promoted_builds.PromotionProcess && " + "build instanceof hudson.model.AbstractBuild && " + "jenkins instanceof jenkins.model.Jenkins", false, null), "", ""));
    p = j.configRoundtrip(p);
    final FreeStyleBuild build = j.buildAndAssertSuccess(p);
    Assert.assertNotNull("Promotion was expected", promotionProcess.isMet(build));
}
Also used : PromotionProcess(hudson.plugins.promoted_builds.PromotionProcess) FreeStyleBuild(hudson.model.FreeStyleBuild) FreeStyleProject(hudson.model.FreeStyleProject) JobPropertyImpl(hudson.plugins.promoted_builds.JobPropertyImpl) SecureGroovyScript(org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SecureGroovyScript) Test(org.junit.Test)

Aggregations

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