Search in sources :

Example 6 with ManualApproval

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

the class ManualConditionTest method testManualPromotionProcessViaWebClient.

public void testManualPromotionProcessViaWebClient() throws Exception {
    FreeStyleProject p = createFreeStyleProject();
    ExtensionList<Descriptor> list = hudson.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 = assertBuildStatusSuccess(p.scheduleBuild2(0));
    assertNull(b1.getAction(ManualApproval.class));
    HtmlPage page = createWebClient().getPage(b1, "promotion");
    //Approve Promotion
    List<HtmlForm> forms = getFormsByName(page, "approve");
    assertFalse(forms.isEmpty());
    assertTrue(forms.size() == 1);
    HtmlForm form = forms.get(0);
    List<HtmlElement> parameters = getFormParameters(form);
    assertTrue(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);
    assertTrue(builds.size() == 1);
    //Re-Execute approved promotion
    page = createWebClient().getPage(b1, "promotion");
    forms = getFormsByName(page, "build");
    assertFalse(forms.isEmpty());
    assertTrue(forms.size() == 1);
    form = forms.get(0);
    parameters = getFormParameters(form);
    assertTrue(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();
    assertTrue(builds.size() == 2);
    List<ManualApproval> actions = b1.getActions(ManualApproval.class);
    assertTrue(actions.size() == 1);
    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();
        assertTrue(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();
        assertTrue(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) ManualCondition(hudson.plugins.promoted_builds.conditions.ManualCondition) HtmlForm(com.gargoylesoftware.htmlunit.html.HtmlForm) DescriptorImpl(hudson.plugins.promoted_builds.JobPropertyImpl.DescriptorImpl) 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)

Example 7 with ManualApproval

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

the class ManualConditionTest method testManualPromotionProcessWithInvalidParam.

@Issue("SECURITY-170")
public /**
     * Verify that the plugin is tolerant against SECURITY-170 in Manual conditions
     */
void testManualPromotionProcessWithInvalidParam() throws Exception {
    FreeStyleProject p = createFreeStyleProject();
    ExtensionList<Descriptor> list = hudson.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("FOO", "BAR", "Test parameter"));
    foo.conditions.add(condition);
    FreeStyleBuild b1 = assertBuildStatusSuccess(p.scheduleBuild2(0));
    // Promote a build. Also add one invalid parameter 
    List<ParameterValue> paramValues = condition.createDefaultValues();
    paramValues.add(new StringParameterValue("INVALID_PARAM", "hacked!"));
    assertBuildStatusSuccess(condition.approve(b1, foo, paramValues));
    ManualApproval manualApproval = b1.getAction(ManualApproval.class);
    assertNotNull(manualApproval);
    List<ParameterValue> parameterValues = manualApproval.badge.getParameterValues();
    // Verify that the build succeeds && has no INVALID_PARAM
    PromotedBuildAction statuses = b1.getAction(PromotedBuildAction.class);
    assertNotNull(statuses);
    assertNotNull(statuses.getPromotions());
    assertFalse(statuses.getPromotions().isEmpty());
    Promotion pb = base.getItem("foo").getBuildByNumber(1);
    assertNotNull("INVALID_PARAM should not be injected into the environment", pb.getEnvironment(TaskListener.NULL).get("INVALID_PARAM", null));
}
Also used : ManualApproval(hudson.plugins.promoted_builds.conditions.ManualCondition.ManualApproval) StringParameterDefinition(hudson.model.StringParameterDefinition) StringParameterValue(hudson.model.StringParameterValue) ParameterValue(hudson.model.ParameterValue) StringParameterValue(hudson.model.StringParameterValue) 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) ManualCondition(hudson.plugins.promoted_builds.conditions.ManualCondition) DescriptorImpl(hudson.plugins.promoted_builds.JobPropertyImpl.DescriptorImpl) PromotionProcess(hudson.plugins.promoted_builds.PromotionProcess) Descriptor(hudson.model.Descriptor) Issue(org.jvnet.hudson.test.Issue)

Example 8 with ManualApproval

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

the class PromotionTargetActionTest method test1.

/**
     * When a project is created, built, and renamed, then the old build is created,
     * that results in NPE.
     */
public void test1() throws Exception {
    FreeStyleProject up = createFreeStyleProject("up");
    up.setCustomWorkspace(createTmpDir().getPath());
    // promote if the downstream passes
    JobPropertyImpl promotion = new JobPropertyImpl(up);
    up.addProperty(promotion);
    PromotionProcess proc = promotion.addProcess("promo");
    proc.conditions.add(new ManualCondition());
    FreeStyleBuild b = assertBuildStatusSuccess(up.scheduleBuild2(0));
    b.addAction(new ManualApproval(proc.getName(), Collections.<ParameterValue>emptyList()));
    b.save();
    // check for promotion
    Promotion p = assertBuildStatusSuccess(proc.considerPromotion2(b));
    up.renameTo("up2");
    assertSame(b, p.getTarget());
}
Also used : ManualCondition(hudson.plugins.promoted_builds.conditions.ManualCondition) ManualApproval(hudson.plugins.promoted_builds.conditions.ManualCondition.ManualApproval) ParameterValue(hudson.model.ParameterValue) FreeStyleBuild(hudson.model.FreeStyleBuild) FreeStyleProject(hudson.model.FreeStyleProject)

Aggregations

ManualApproval (hudson.plugins.promoted_builds.conditions.ManualCondition.ManualApproval)8 Descriptor (hudson.model.Descriptor)6 StringParameterDefinition (hudson.model.StringParameterDefinition)6 JobPropertyImpl (hudson.plugins.promoted_builds.JobPropertyImpl)6 PromotedBuildAction (hudson.plugins.promoted_builds.PromotedBuildAction)6 PromotionProcess (hudson.plugins.promoted_builds.PromotionProcess)6 ManualCondition (hudson.plugins.promoted_builds.conditions.ManualCondition)6 FreeStyleBuild (hudson.model.FreeStyleBuild)5 FreeStyleProject (hudson.model.FreeStyleProject)5 ParameterValue (hudson.model.ParameterValue)5 Promotion (hudson.plugins.promoted_builds.Promotion)4 ParameterDefinition (hudson.model.ParameterDefinition)3 StringParameterValue (hudson.model.StringParameterValue)3 DescriptorImpl (hudson.plugins.promoted_builds.JobPropertyImpl.DescriptorImpl)3 ArrayList (java.util.ArrayList)3 HtmlElement (com.gargoylesoftware.htmlunit.html.HtmlElement)2 HtmlForm (com.gargoylesoftware.htmlunit.html.HtmlForm)2 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)2 InheritanceBuild (hudson.plugins.project_inheritance.projects.InheritanceBuild)2 Status (hudson.plugins.promoted_builds.Status)2