use of hudson.model.FreeStyleBuild in project promoted-builds-plugin by jenkinsci.
the class GroovyConditionTest method testBooleanScript.
@Test
public void testBooleanScript() throws Exception {
FreeStyleProject p = j.createFreeStyleProject();
final JobPropertyImpl property = new JobPropertyImpl(p);
final PromotionProcess promotionProcessTrue = property.addProcess("truePromotion");
promotionProcessTrue.conditions.add(new GroovyCondition(new SecureGroovyScript("true", false, null), "", ""));
final PromotionProcess promotionProcessFalse = property.addProcess("falsePromotion");
promotionProcessFalse.conditions.add(new GroovyCondition(new SecureGroovyScript("false", false, null), "", ""));
p = j.configRoundtrip(p);
final FreeStyleBuild build = j.buildAndAssertSuccess(p);
Assert.assertNotNull("Promotion was expected", promotionProcessTrue.isMet(build));
Assert.assertNull("Promotion was not expected", promotionProcessFalse.isMet(build));
}
use of hudson.model.FreeStyleBuild 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());
}
}
use of hudson.model.FreeStyleBuild 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));
}
use of hudson.model.FreeStyleBuild in project promoted-builds-plugin by jenkinsci.
the class SelfPromotionTest method testFailure.
public void testFailure() throws Exception {
FreeStyleProject p = createFreeStyleProject();
// promote if the downstream passes
JobPropertyImpl promotion = new JobPropertyImpl(p);
p.addProperty(promotion);
PromotionProcess promo1 = promotion.addProcess("promo1");
promo1.conditions.add(new SelfPromotionCondition(false));
PromotionProcess promo2 = promotion.addProcess("promo2");
promo2.conditions.add(new SelfPromotionCondition(true));
// ensure that the data survives the roundtrip
configRoundtrip(p);
// rebind
promotion = p.getProperty(JobPropertyImpl.class);
promo1 = promotion.getItem("promo1");
promo2 = promotion.getItem("promo2");
p.getBuildersList().add(failureBuilder());
FreeStyleBuild b = assertBuildStatus(Result.FAILURE, p.scheduleBuild2(0).get());
// internally, the promotion is still an asynchronous process. It just happens
// right away after the build is complete.
Thread.sleep(1000);
// verify that neither promotions happened
assertTrue("promo1 did not occur", promo1.getBuilds().isEmpty());
assertTrue("promo2 did not occur", promo2.getBuilds().isEmpty());
PromotedBuildAction badge = (PromotedBuildAction) b.getBadgeActions().get(0);
assertFalse(badge.contains(promo1));
assertFalse(badge.contains(promo2));
}
use of hudson.model.FreeStyleBuild in project promoted-builds-plugin by jenkinsci.
the class SelfPromotionTest method testBasic.
public void testBasic() throws Exception {
FreeStyleProject p = createFreeStyleProject();
// promote if the downstream passes
JobPropertyImpl promotion = new JobPropertyImpl(p);
p.addProperty(promotion);
PromotionProcess promo1 = promotion.addProcess("promo1");
promo1.conditions.add(new SelfPromotionCondition(false));
PromotionProcess promo2 = promotion.addProcess("promo2");
promo2.conditions.add(new SelfPromotionCondition(false));
// ensure that the data survives the roundtrip
configRoundtrip(p);
// rebind
promotion = p.getProperty(JobPropertyImpl.class);
promo1 = promotion.getItem("promo1");
promo2 = promotion.getItem("promo2");
FreeStyleBuild b = assertBuildStatusSuccess(p.scheduleBuild2(0));
// internally, the promotion is still an asynchronous process. It just happens
// right away after the build is complete.
Thread.sleep(1000);
// verify that both promotions happened
Promotion pb = promo1.getBuilds().get(0);
assertSame(pb.getTarget(), b);
pb = promo2.getBuilds().get(0);
assertSame(pb.getTarget(), b);
PromotedBuildAction badge = (PromotedBuildAction) b.getBadgeActions().get(0);
assertTrue(badge.contains(promo1));
assertTrue(badge.contains(promo2));
}
Aggregations