Search in sources :

Example 1 with SecureGroovyScript

use of org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SecureGroovyScript 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)

Example 2 with SecureGroovyScript

use of org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SecureGroovyScript 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));
}
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)

Example 3 with SecureGroovyScript

use of org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SecureGroovyScript 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));
}
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)3 FreeStyleProject (hudson.model.FreeStyleProject)3 JobPropertyImpl (hudson.plugins.promoted_builds.JobPropertyImpl)3 PromotionProcess (hudson.plugins.promoted_builds.PromotionProcess)3 SecureGroovyScript (org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SecureGroovyScript)3 Test (org.junit.Test)3