Search in sources :

Example 1 with PromotionProcess

use of hudson.plugins.promoted_builds.PromotionProcess 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 2 with PromotionProcess

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));
}
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 PromotionProcess

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());
}
Also used : ManualApproval(hudson.plugins.promoted_builds.conditions.ManualCondition.ManualApproval) StringParameterDefinition(hudson.model.StringParameterDefinition) StringParameterValue(hudson.model.StringParameterValue) ParameterValue(hudson.model.ParameterValue) FreeStyleBuild(hudson.model.FreeStyleBuild) PromotedBuildAction(hudson.plugins.promoted_builds.PromotedBuildAction) FreeStyleProject(hudson.model.FreeStyleProject) JobPropertyImpl(hudson.plugins.promoted_builds.JobPropertyImpl) PromotionProcess(hudson.plugins.promoted_builds.PromotionProcess) Descriptor(hudson.model.Descriptor) Test(org.junit.Test)

Example 4 with PromotionProcess

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());
    }
}
Also used : ManualApproval(hudson.plugins.promoted_builds.conditions.ManualCondition.ManualApproval) PromotionProcess(hudson.plugins.promoted_builds.PromotionProcess) FailingHttpStatusCodeException(com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException) FreeStyleBuild(hudson.model.FreeStyleBuild) FreeStyleProject(hudson.model.FreeStyleProject) WebClient(org.jvnet.hudson.test.JenkinsRule.WebClient) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 5 with PromotionProcess

use of hudson.plugins.promoted_builds.PromotionProcess 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)

Aggregations

PromotionProcess (hudson.plugins.promoted_builds.PromotionProcess)23 Test (org.junit.Test)22 JobPropertyImpl (hudson.plugins.promoted_builds.JobPropertyImpl)20 FreeStyleBuild (hudson.model.FreeStyleBuild)15 FreeStyleProject (hudson.model.FreeStyleProject)15 PromotedBuildAction (hudson.plugins.promoted_builds.PromotedBuildAction)14 Promotion (hudson.plugins.promoted_builds.Promotion)11 StringParameterDefinition (hudson.model.StringParameterDefinition)10 ManualApproval (hudson.plugins.promoted_builds.conditions.ManualCondition.ManualApproval)8 InheritanceProjectsPair (hudson.plugins.promoted_builds.inheritance.helpers.InheritanceProjectsPair)7 Descriptor (hudson.model.Descriptor)6 InheritanceBuild (hudson.plugins.project_inheritance.projects.InheritanceBuild)6 Issue (org.jvnet.hudson.test.Issue)6 StringParameterValue (hudson.model.StringParameterValue)5 ParameterValue (hudson.model.ParameterValue)4 Status (hudson.plugins.promoted_builds.Status)4 SelfPromotionCondition (hudson.plugins.promoted_builds.conditions.SelfPromotionCondition)4 ParameterDefinition (hudson.model.ParameterDefinition)3 ManualCondition (hudson.plugins.promoted_builds.conditions.ManualCondition)3 SecureGroovyScript (org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SecureGroovyScript)3