use of hudson.plugins.promoted_builds.PromotionProcess 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));
}
use of hudson.plugins.promoted_builds.PromotionProcess in project promoted-builds-plugin by jenkinsci.
the class ManualConditionTest method testManualPromotionProcess.
@Test
public void testManualPromotionProcess() 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));
// promote a build
List<ParameterValue> paramValues = condition.createDefaultValues();
// try to add duplicate values
paramValues.addAll(condition.createDefaultValues());
j.assertBuildStatusSuccess(condition.approve(b1, foo, paramValues));
ManualApproval manualApproval = b1.getAction(ManualApproval.class);
assertNotNull(manualApproval);
PromotedBuildAction statuses = b1.getAction(PromotedBuildAction.class);
assertNotNull(statuses);
assertNotNull(statuses.getPromotions());
assertFalse(statuses.getPromotions().isEmpty());
}
use of hudson.plugins.promoted_builds.PromotionProcess in project promoted-builds-plugin by jenkinsci.
the class ManualConditionTest method testManualPromotionPermissionsViaWebClient.
@Test
// TODO figure out a good way to test this with SECURITY-2293
@Ignore
public void testManualPromotionPermissionsViaWebClient() throws Exception {
enableSecurity(j);
FreeStyleProject p = j.createFreeStyleProject();
PromotionProcess pp = addPromotionProcess(p, "foo");
WebClient wc = j.createWebClient();
FreeStyleBuild b = j.assertBuildStatusSuccess(p.scheduleBuild2(0));
ManualCondition cond = new ManualCondition();
pp.conditions.add(cond);
j.assertBuildStatusSuccess(cond.approve(b, pp, Collections.EMPTY_LIST));
assertThat(b.getAction(ManualApproval.class), notNullValue());
{
// Re-execute promotion as user without Promotion/Promote when no users are specified
wc.login("non-promoter", "non-promoter");
// Status#doBuild does a bare `return;` without scheduling the build in this case, which is why we use goTo with "" for the MIME type.
wc.goTo(String.format("job/%s/%d/promotion/%s/build?json={}", p.getName(), b.getNumber(), pp.getName()), "");
assertThat(pp.getBuildByNumber(2), nullValue());
}
{
// Re-execute promotion as user with Promotion/Promote when no users are specified
wc.login("promoter", "promoter");
try {
wc.getPage(b, String.format("promotion/%s/build?json={}", pp.getName()));
fail();
} catch (FailingHttpStatusCodeException e) {
// Redirect after the build is broken.
assertThat(e.getStatusCode(), equalTo(404));
}
assertThat(waitForBuildByNumber(pp, 2).getResult(), equalTo(Result.SUCCESS));
}
{
// Re-execute promotion as specified user without Promotion/Promote
cond.setUsers("non-promoter");
wc.login("non-promoter", "non-promoter");
try {
wc.getPage(b, String.format("promotion/%s/build?json={}", pp.getName()));
fail();
} catch (FailingHttpStatusCodeException e) {
// Redirect after the build is broken.
assertThat(e.getStatusCode(), equalTo(404));
}
assertThat(waitForBuildByNumber(pp, 3).getResult(), equalTo(Result.SUCCESS));
}
{
// Re-execute promotion as unspecified user with Promotion/Promote
cond.setUsers("non-promoter");
wc.login("promoter", "promoter");
// Status#doBuild does a bare `return;` without scheduling the build in this case, which is why we use goTo with "" for the MIME type.
wc.goTo(String.format("job/%s/%d/promotion/%s/build?json={}", p.getName(), b.getNumber(), pp.getName()), "");
assertThat(pp.getBuildByNumber(4), nullValue());
}
}
use of hudson.plugins.promoted_builds.PromotionProcess 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.plugins.promoted_builds.PromotionProcess in project promoted-builds-plugin by jenkinsci.
the class GroovyConditionTest method testMapScript.
@Test
public void testMapScript() throws Exception {
FreeStyleProject p = j.createFreeStyleProject();
final JobPropertyImpl property = new JobPropertyImpl(p);
final PromotionProcess promotionProcessEmptyMap = property.addProcess("emptyMap");
promotionProcessEmptyMap.conditions.add(new GroovyCondition(new SecureGroovyScript("[:]", false, null), "", ""));
final PromotionProcess promotionProcessNonEmptyMap = property.addProcess("nonEmptyMap");
promotionProcessNonEmptyMap.conditions.add(new GroovyCondition(new SecureGroovyScript("[foo: 'bar']", false, null), "", ""));
p = j.configRoundtrip(p);
final FreeStyleBuild build = j.buildAndAssertSuccess(p);
Assert.assertNull("Promotion was not expected", promotionProcessEmptyMap.isMet(build));
Assert.assertNotNull("Promotion was expected", promotionProcessNonEmptyMap.isMet(build));
}
Aggregations