Search in sources :

Example 1 with Status

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

the class UpstreamPromotionCondition method isMet.

@Override
public PromotionBadge isMet(PromotionProcess promotionProcess, AbstractBuild<?, ?> build) {
    Badge badge = new Badge();
    Set<String> requiredPromotions = getRequiredPromotionNamesAsSet();
    if (requiredPromotions.isEmpty()) {
        return badge;
    }
    PromotedBuildAction pba = build.getAction(PromotedBuildAction.class);
    if (pba == null) {
        return null;
    }
    for (Status status : pba.getPromotions()) {
        if (status.isPromotionSuccessful()) {
            requiredPromotions.remove(status.getName());
            badge.add(status.getName());
            // short circuit for loop if
            if (requiredPromotions.isEmpty())
                break;
        }
    }
    return requiredPromotions.isEmpty() ? badge : null;
}
Also used : Status(hudson.plugins.promoted_builds.Status) PromotedBuildAction(hudson.plugins.promoted_builds.PromotedBuildAction) PromotionBadge(hudson.plugins.promoted_builds.PromotionBadge)

Example 2 with Status

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

the class DownstreamPassConditionTest method shouldEvaluateUpstreamRecursively.

@Test
@Issue("JENKINS-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) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test)

Example 3 with Status

use of hudson.plugins.promoted_builds.Status 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 4 with Status

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

the class ManualConditionBug22005 method testPromotionProcess.

@Test
public void testPromotionProcess() throws Exception {
    FreeStyleProject p = j.createFreeStyleProject();
    ExtensionList<Descriptor> list = j.jenkins.getExtensionList(Descriptor.class);
    list.add(new JobPropertyImpl.DescriptorImpl(JobPropertyImpl.class));
    JobPropertyImpl base = new JobPropertyImpl(p);
    p.addProperty(base);
    PromotionProcess prom0 = createPromotionProcess(base, "PROM0");
    ManualCondition prom0Condition = prom0.conditions.get(ManualCondition.class);
    PromotionProcess prom1 = createPromotionProcess(base, "PROM1");
    ManualCondition prom1Condition = prom1.conditions.get(ManualCondition.class);
    PromotionProcess prom2 = createPromotionProcess(base, "PROM2");
    ManualCondition prom2Condition = prom2.conditions.get(ManualCondition.class);
    FreeStyleBuild b1 = j.assertBuildStatusSuccess(p.scheduleBuild2(0));
    Promotion p0b1 = j.assertBuildStatusSuccess(prom0Condition.approve(b1, prom0));
    assertEquals(2, p0b1.getParameterValues().size());
    assertEquals(2, p0b1.getParameterDefinitionsWithValue().size());
    Promotion p1b1 = j.assertBuildStatusSuccess(prom1Condition.approve(b1, prom1));
    assertEquals(2, p1b1.getParameterValues().size());
    assertEquals(2, p1b1.getParameterDefinitionsWithValue().size());
    Promotion p2b1 = j.assertBuildStatusSuccess(prom2Condition.approve(b1, prom2));
    assertEquals(2, p2b1.getParameterValues().size());
    assertEquals(2, p2b1.getParameterDefinitionsWithValue().size());
    List<ManualApproval> approvals = b1.getActions(ManualApproval.class);
    assertEquals(3, approvals.size());
    PromotedBuildAction promBuildAction = b1.getAction(PromotedBuildAction.class);
    List<Status> statuses = promBuildAction.getPromotions();
    assertEquals(3, statuses.size());
    for (Status status : statuses) {
        Promotion lastBuild = status.getLast();
        List<ParameterDefinition> lastBuildParameters = lastBuild.getParameterDefinitionsWithValue();
        assertEquals(2, lastBuildParameters.size());
    }
}
Also used : Status(hudson.plugins.promoted_builds.Status) ManualApproval(hudson.plugins.promoted_builds.conditions.ManualCondition.ManualApproval) FreeStyleBuild(hudson.model.FreeStyleBuild) PromotedBuildAction(hudson.plugins.promoted_builds.PromotedBuildAction) FreeStyleProject(hudson.model.FreeStyleProject) JobPropertyImpl(hudson.plugins.promoted_builds.JobPropertyImpl) Promotion(hudson.plugins.promoted_builds.Promotion) PromotionProcess(hudson.plugins.promoted_builds.PromotionProcess) Descriptor(hudson.model.Descriptor) ParameterDefinition(hudson.model.ParameterDefinition) StringParameterDefinition(hudson.model.StringParameterDefinition) Test(org.junit.Test)

Example 5 with Status

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

the class ManualConditionTest method testManualPromotionProcessViaWebClient.

@Test
public void testManualPromotionProcessViaWebClient() throws Exception {
    FreeStyleProject p = j.createFreeStyleProject();
    ExtensionList<Descriptor> list = j.jenkins.getExtensionList(Descriptor.class);
    list.add(new JobPropertyImpl.DescriptorImpl(JobPropertyImpl.class));
    JobPropertyImpl base = new JobPropertyImpl(p);
    p.addProperty(base);
    PromotionProcess foo = base.addProcess("foo");
    ManualCondition condition = new ManualCondition();
    condition.getParameterDefinitions().add(new StringParameterDefinition("bogus_string_param_1", "bogus_value_1", "Bog parameter"));
    condition.getParameterDefinitions().add(new StringParameterDefinition("bogus_string_param_2", "bogus_value_2", "Bog parameter"));
    foo.conditions.add(condition);
    FreeStyleBuild b1 = j.assertBuildStatusSuccess(p.scheduleBuild2(0));
    assertNull(b1.getAction(ManualApproval.class));
    HtmlPage page = j.createWebClient().getPage(b1, "promotion");
    // Approve Promotion
    List<HtmlForm> forms = getFormsByName(page, "approve");
    assertFalse(forms.isEmpty());
    assertEquals(1, forms.size());
    HtmlForm form = forms.get(0);
    List<HtmlElement> parameters = getFormParameters(form);
    assertEquals(parameters.size(), condition.getParameterDefinitions().size());
    for (HtmlElement param : parameters) {
        HtmlElement v = param.getElementsByAttribute("input", "name", "value").get(0);
        v.setAttribute("value", v.getAttribute("value") + "1");
    }
    submit(forms.get(0));
    ManualApproval approval = b1.getAction(ManualApproval.class);
    assertNotNull(approval);
    SortedMap<Integer, Promotion> builds = foo.getBuildsAsMap();
    assertNotNull(builds);
    assertEquals(1, builds.size());
    // Re-Execute approved promotion
    page = j.createWebClient().getPage(b1, "promotion");
    forms = getFormsByName(page, "build");
    assertFalse(forms.isEmpty());
    assertEquals(1, forms.size());
    form = forms.get(0);
    parameters = getFormParameters(form);
    assertEquals(parameters.size(), condition.getParameterDefinitions().size());
    for (HtmlElement param : parameters) {
        HtmlElement v = param.getElementsByAttribute("input", "name", "value").get(0);
        v.setAttribute("value", v.getAttribute("value") + "2");
    }
    submit(form);
    builds = foo.getBuildsAsMap();
    assertEquals(2, builds.size());
    List<ManualApproval> actions = b1.getActions(ManualApproval.class);
    assertEquals(1, actions.size());
    PromotedBuildAction buildActions = b1.getAction(PromotedBuildAction.class);
    int buildIndex = 1;
    String valueSufix = "1";
    List<Promotion> promotions = new ArrayList<Promotion>();
    promotions.addAll(builds.values());
    Collections.reverse(promotions);
    for (Promotion build : promotions) {
        List<ParameterDefinition> values = build.getParameterDefinitionsWithValue();
        assertEquals(values.size(), condition.getParameterDefinitions().size());
        for (ParameterDefinition v : values) {
            assertTrue(v instanceof StringParameterDefinition);
            String pvalue = ((StringParameterDefinition) v).getDefaultValue();
            assertTrue(pvalue.endsWith(valueSufix));
        }
        buildIndex++;
        valueSufix += buildIndex;
    }
    for (Status status : buildActions.getPromotions()) {
        assertNotNull(status.getLast() != null);
        List<ParameterDefinition> values = status.getLast().getParameterDefinitionsWithValue();
        assertEquals(values.size(), condition.getParameterDefinitions().size());
    }
}
Also used : StringParameterDefinition(hudson.model.StringParameterDefinition) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) ArrayList(java.util.ArrayList) FreeStyleBuild(hudson.model.FreeStyleBuild) Promotion(hudson.plugins.promoted_builds.Promotion) HtmlForm(com.gargoylesoftware.htmlunit.html.HtmlForm) PromotionProcess(hudson.plugins.promoted_builds.PromotionProcess) Status(hudson.plugins.promoted_builds.Status) ManualApproval(hudson.plugins.promoted_builds.conditions.ManualCondition.ManualApproval) HtmlElement(com.gargoylesoftware.htmlunit.html.HtmlElement) PromotedBuildAction(hudson.plugins.promoted_builds.PromotedBuildAction) FreeStyleProject(hudson.model.FreeStyleProject) JobPropertyImpl(hudson.plugins.promoted_builds.JobPropertyImpl) Descriptor(hudson.model.Descriptor) ParameterDefinition(hudson.model.ParameterDefinition) StringParameterDefinition(hudson.model.StringParameterDefinition) Test(org.junit.Test)

Aggregations

PromotedBuildAction (hudson.plugins.promoted_builds.PromotedBuildAction)5 Status (hudson.plugins.promoted_builds.Status)5 JobPropertyImpl (hudson.plugins.promoted_builds.JobPropertyImpl)4 PromotionProcess (hudson.plugins.promoted_builds.PromotionProcess)4 Test (org.junit.Test)4 FreeStyleBuild (hudson.model.FreeStyleBuild)3 FreeStyleProject (hudson.model.FreeStyleProject)3 Descriptor (hudson.model.Descriptor)2 ParameterDefinition (hudson.model.ParameterDefinition)2 StringParameterDefinition (hudson.model.StringParameterDefinition)2 Promotion (hudson.plugins.promoted_builds.Promotion)2 ManualApproval (hudson.plugins.promoted_builds.conditions.ManualCondition.ManualApproval)2 BuildTrigger (hudson.tasks.BuildTrigger)2 Issue (org.jvnet.hudson.test.Issue)2 HtmlElement (com.gargoylesoftware.htmlunit.html.HtmlElement)1 HtmlForm (com.gargoylesoftware.htmlunit.html.HtmlForm)1 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)1 InheritanceBuild (hudson.plugins.project_inheritance.projects.InheritanceBuild)1 PromotionBadge (hudson.plugins.promoted_builds.PromotionBadge)1 DownstreamPassCondition (hudson.plugins.promoted_builds.conditions.DownstreamPassCondition)1