Search in sources :

Example 1 with SelfPromotionCondition

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

the class SelfPromotionInheritanceTest method testBasic.

@Test
public void testBasic() throws Exception {
    InheritanceProjectsPair inheritanceProjectPair = j.createInheritanceProjectDerivedWithBase();
    // promote if the downstream passes
    JobPropertyImpl promotion = new JobPropertyImpl(inheritanceProjectPair.getBase());
    inheritanceProjectPair.getBase().addProperty(promotion);
    PromotionProcess promo1 = promotion.addProcess("promo1");
    promo1.conditions.add(new SelfPromotionCondition(false));
    PromotionProcess promo2 = promotion.addProcess("promo2");
    promo2.conditions.add(new SelfPromotionCondition(false));
    InheritanceBuild b = j.assertBuildStatusSuccess(inheritanceProjectPair.getDerived().scheduleBuild2(0));
    // internally, the promotion is still an asynchronous process. It just happens
    // right away after the build is complete.
    j.waitUntilNoActivity();
    // rebind
    promotion = inheritanceProjectPair.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);
    promo1 = promotion.getItem("promo1");
    promo2 = promotion.getItem("promo2");
    // 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));
}
Also used : InheritanceProjectsPair(hudson.plugins.promoted_builds.inheritance.helpers.InheritanceProjectsPair) InheritanceBuild(hudson.plugins.project_inheritance.projects.InheritanceBuild) PromotionProcess(hudson.plugins.promoted_builds.PromotionProcess) SelfPromotionCondition(hudson.plugins.promoted_builds.conditions.SelfPromotionCondition) PromotedBuildAction(hudson.plugins.promoted_builds.PromotedBuildAction) JobPropertyImpl(hudson.plugins.promoted_builds.JobPropertyImpl) Promotion(hudson.plugins.promoted_builds.Promotion) Test(org.junit.Test)

Example 2 with SelfPromotionCondition

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

the class SelfPromotionInheritanceTest method testFailure.

@Test
public void testFailure() throws Exception {
    InheritanceProjectsPair inheritanceProjectPair = j.createInheritanceProjectDerivedWithBase();
    // promote if the downstream passes
    JobPropertyImpl promotion = new JobPropertyImpl(inheritanceProjectPair.getBase());
    inheritanceProjectPair.getBase().addProperty(promotion);
    PromotionProcess promo1 = promotion.addProcess("promo1");
    promo1.conditions.add(new SelfPromotionCondition(false));
    PromotionProcess promo2 = promotion.addProcess("promo2");
    promo2.conditions.add(new SelfPromotionCondition(true));
    inheritanceProjectPair.getDerived().getBuildersList().add(failureBuilder());
    InheritanceBuild b = j.assertBuildStatus(Result.FAILURE, inheritanceProjectPair.getDerived().scheduleBuild2(0).get());
    // internally, the promotion is still an asynchronous process. It just happens
    // right away after the build is complete.
    j.waitUntilNoActivity();
    // rebind
    promotion = inheritanceProjectPair.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);
    promo1 = promotion.getItem("promo1");
    promo2 = promotion.getItem("promo2");
    // 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));
}
Also used : InheritanceProjectsPair(hudson.plugins.promoted_builds.inheritance.helpers.InheritanceProjectsPair) InheritanceBuild(hudson.plugins.project_inheritance.projects.InheritanceBuild) PromotionProcess(hudson.plugins.promoted_builds.PromotionProcess) SelfPromotionCondition(hudson.plugins.promoted_builds.conditions.SelfPromotionCondition) PromotedBuildAction(hudson.plugins.promoted_builds.PromotedBuildAction) JobPropertyImpl(hudson.plugins.promoted_builds.JobPropertyImpl) Test(org.junit.Test)

Example 3 with SelfPromotionCondition

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

the class SelfPromotionInheritanceTest method testPromotionEnvironmentShouldIncludeTargetParameters.

@Test
@Bug(22679)
public void testPromotionEnvironmentShouldIncludeTargetParameters() throws Exception {
    String paramName = "param";
    InheritanceProjectsPair inheritanceProjectPair = j.createInheritanceProjectDerivedWithBase();
    // promote if the downstream passes
    JobPropertyImpl promotion = new JobPropertyImpl(inheritanceProjectPair.getBase());
    inheritanceProjectPair.getBase().addProperty(promotion);
    // TODO review this property asignment after https://issues.jenkins-ci.org/browse/JENKINS-34831 is fixed
    inheritanceProjectPair.getBase().addProperty(new ParametersDefinitionProperty(new StringParameterDefinition(paramName, "")));
    inheritanceProjectPair.getDerived().addProperty(new ParametersDefinitionProperty(new StringParameterDefinition(paramName, "")));
    PromotionProcess promo1 = promotion.addProcess("promo1");
    promo1.conditions.add(new SelfPromotionCondition(false));
    // fire ItemListeners, this includes ArtifactArchiver,Migrator to make this test compatible with jenkins 1.575+
    fireItemListeners();
    String paramValue = "someString";
    j.assertBuildStatusSuccess(inheritanceProjectPair.getDerived().scheduleBuild2(0, new Cause.UserCause(), new ParametersAction(new StringParameterValue(paramName, paramValue))));
    // internally, the promotion is still an asynchronous process. It just happens
    // right away after the build is complete.
    j.waitUntilNoActivity();
    // rebind
    promotion = inheritanceProjectPair.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);
    promo1 = promotion.getItem("promo1");
    // verify that the promotion's environment contains the parameter from the target build.
    Promotion pb = promo1.getBuildByNumber(1);
    assertEquals(paramValue, pb.getEnvironment(TaskListener.NULL).get(paramName, null));
}
Also used : InheritanceProjectsPair(hudson.plugins.promoted_builds.inheritance.helpers.InheritanceProjectsPair) StringParameterDefinition(hudson.model.StringParameterDefinition) ParametersDefinitionProperty(hudson.model.ParametersDefinitionProperty) PromotionProcess(hudson.plugins.promoted_builds.PromotionProcess) StringParameterValue(hudson.model.StringParameterValue) SelfPromotionCondition(hudson.plugins.promoted_builds.conditions.SelfPromotionCondition) JobPropertyImpl(hudson.plugins.promoted_builds.JobPropertyImpl) Promotion(hudson.plugins.promoted_builds.Promotion) ParametersAction(hudson.model.ParametersAction) Test(org.junit.Test) Bug(org.jvnet.hudson.test.Bug)

Example 4 with SelfPromotionCondition

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

the class RemoteApiTest method getAndModify.

@Test
public void getAndModify() throws Exception {
    FreeStyleProject p = r.createFreeStyleProject("p");
    JobPropertyImpl promotion = new JobPropertyImpl(p);
    p.addProperty(promotion);
    PromotionProcess proc = promotion.addProcess("promo");
    proc.conditions.add(new SelfPromotionCondition(true));
    JenkinsRule.WebClient wc = r.createWebClient();
    String xml = wc.goToXml("job/p/promotion/process/promo/config.xml").getContent();
    assertTrue(xml, xml.contains("SelfPromotionCondition"));
    assertTrue(xml, xml.contains("<evenIfUnstable>true</evenIfUnstable>"));
    WebRequest req = new WebRequest(wc.createCrumbedUrl("job/p/promotion/process/promo/config.xml"), HttpMethod.POST);
    req.setEncodingType(null);
    req.setRequestBody(xml.replace("<evenIfUnstable>true</evenIfUnstable>", "<evenIfUnstable>false</evenIfUnstable>"));
    assertTrue(proc.conditions.get(SelfPromotionCondition.class).isEvenIfUnstable());
    wc.getPage(req);
    assertFalse(proc.conditions.get(SelfPromotionCondition.class).isEvenIfUnstable());
}
Also used : WebRequest(com.gargoylesoftware.htmlunit.WebRequest) SelfPromotionCondition(hudson.plugins.promoted_builds.conditions.SelfPromotionCondition) JenkinsRule(org.jvnet.hudson.test.JenkinsRule) FreeStyleProject(hudson.model.FreeStyleProject) Test(org.junit.Test)

Example 5 with SelfPromotionCondition

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

the class SelfPromotionInheritanceTest method testUnstable.

@Test
public void testUnstable() throws Exception {
    InheritanceProjectsPair inheritanceProjectPair = j.createInheritanceProjectDerivedWithBase();
    // promote if the downstream passes
    JobPropertyImpl promotion = new JobPropertyImpl(inheritanceProjectPair.getBase());
    inheritanceProjectPair.getBase().addProperty(promotion);
    PromotionProcess promo1 = promotion.addProcess("promo1");
    promo1.conditions.add(new SelfPromotionCondition(false));
    PromotionProcess promo2 = promotion.addProcess("promo2");
    promo2.conditions.add(new SelfPromotionCondition(true));
    inheritanceProjectPair.getDerived().getBuildersList().add(unstableBuilder());
    InheritanceBuild b = j.assertBuildStatus(Result.UNSTABLE, inheritanceProjectPair.getDerived().scheduleBuild2(0).get());
    j.waitUntilNoActivity();
    // rebind
    promotion = inheritanceProjectPair.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);
    promo1 = promotion.getItem("promo1");
    promo2 = promotion.getItem("promo2");
    // internally, the promotion is still an asynchronous process. It just happens
    // right away after the build is complete.
    // verify that only one promotions happened
    assertTrue(promo1.getBuilds().isEmpty());
    Promotion pb = promo2.getBuilds().get(0);
    assertSame(pb.getTarget(), b);
    PromotedBuildAction badge = (PromotedBuildAction) b.getBadgeActions().get(0);
    assertFalse(badge.contains(promo1));
    assertTrue(badge.contains(promo2));
}
Also used : InheritanceProjectsPair(hudson.plugins.promoted_builds.inheritance.helpers.InheritanceProjectsPair) InheritanceBuild(hudson.plugins.project_inheritance.projects.InheritanceBuild) PromotionProcess(hudson.plugins.promoted_builds.PromotionProcess) SelfPromotionCondition(hudson.plugins.promoted_builds.conditions.SelfPromotionCondition) PromotedBuildAction(hudson.plugins.promoted_builds.PromotedBuildAction) JobPropertyImpl(hudson.plugins.promoted_builds.JobPropertyImpl) Promotion(hudson.plugins.promoted_builds.Promotion) Test(org.junit.Test)

Aggregations

SelfPromotionCondition (hudson.plugins.promoted_builds.conditions.SelfPromotionCondition)8 Test (org.junit.Test)7 JobPropertyImpl (hudson.plugins.promoted_builds.JobPropertyImpl)4 PromotionProcess (hudson.plugins.promoted_builds.PromotionProcess)4 InheritanceProjectsPair (hudson.plugins.promoted_builds.inheritance.helpers.InheritanceProjectsPair)4 InheritanceBuild (hudson.plugins.project_inheritance.projects.InheritanceBuild)3 PromotedBuildAction (hudson.plugins.promoted_builds.PromotedBuildAction)3 Promotion (hudson.plugins.promoted_builds.Promotion)3 JenkinsRule (org.jvnet.hudson.test.JenkinsRule)2 WebRequest (com.gargoylesoftware.htmlunit.WebRequest)1 HtmlForm (com.gargoylesoftware.htmlunit.html.HtmlForm)1 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)1 Node (groovy.util.Node)1 FreeStyleProject (hudson.model.FreeStyleProject)1 ParametersAction (hudson.model.ParametersAction)1 ParametersDefinitionProperty (hudson.model.ParametersDefinitionProperty)1 StringParameterDefinition (hudson.model.StringParameterDefinition)1 StringParameterValue (hudson.model.StringParameterValue)1 PromotionCondition (hudson.plugins.promoted_builds.PromotionCondition)1 DownstreamPassCondition (hudson.plugins.promoted_builds.conditions.DownstreamPassCondition)1