Search in sources :

Example 1 with InheritanceProjectsPair

use of hudson.plugins.promoted_builds.inheritance.helpers.InheritanceProjectsPair in project promoted-builds-plugin by jenkinsci.

the class ManualConditionInheritanceTest method testManualPromotionProcess.

@Test
public void testManualPromotionProcess() throws Exception {
    InheritanceProjectsPair inheritanceProjectsPair = j.createInheritanceProjectDerivedWithBase();
    ExtensionList<Descriptor> list = Jenkins.getInstance().getExtensionList(Descriptor.class);
    list.add(new JobPropertyImpl.DescriptorImpl(JobPropertyImpl.class));
    JobPropertyImpl base = new JobPropertyImpl(inheritanceProjectsPair.getBase());
    inheritanceProjectsPair.getBase().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);
    InheritanceBuild b1 = j.assertBuildStatusSuccess(inheritanceProjectsPair.getDerived().scheduleBuild2(0));
    // promote a build
    List<ParameterValue> paramValues = condition.createDefaultValues();
    //try to add duplicate values
    paramValues.addAll(condition.createDefaultValues());
    //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 = inheritanceProjectsPair.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 fooDerived = jobProperty.getItem("foo");
    j.assertBuildStatusSuccess(condition.approve(b1, fooDerived, 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 : InheritanceProjectsPair(hudson.plugins.promoted_builds.inheritance.helpers.InheritanceProjectsPair) ManualApproval(hudson.plugins.promoted_builds.conditions.ManualCondition.ManualApproval) InheritanceBuild(hudson.plugins.project_inheritance.projects.InheritanceBuild) StringParameterDefinition(hudson.model.StringParameterDefinition) ParameterValue(hudson.model.ParameterValue) PromotedBuildAction(hudson.plugins.promoted_builds.PromotedBuildAction) JobPropertyImpl(hudson.plugins.promoted_builds.JobPropertyImpl) ManualCondition(hudson.plugins.promoted_builds.conditions.ManualCondition) PromotionProcess(hudson.plugins.promoted_builds.PromotionProcess) Descriptor(hudson.model.Descriptor) Test(org.junit.Test)

Example 2 with InheritanceProjectsPair

use of hudson.plugins.promoted_builds.inheritance.helpers.InheritanceProjectsPair 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 3 with InheritanceProjectsPair

use of hudson.plugins.promoted_builds.inheritance.helpers.InheritanceProjectsPair 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 4 with InheritanceProjectsPair

use of hudson.plugins.promoted_builds.inheritance.helpers.InheritanceProjectsPair 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 5 with InheritanceProjectsPair

use of hudson.plugins.promoted_builds.inheritance.helpers.InheritanceProjectsPair in project promoted-builds-plugin by jenkinsci.

the class DownstreamPassConditionInheritanceTest method shouldEvaluateUpstreamRecursively.

@Test
@Bug(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) Test(org.junit.Test) Bug(org.jvnet.hudson.test.Bug)

Aggregations

JobPropertyImpl (hudson.plugins.promoted_builds.JobPropertyImpl)7 PromotionProcess (hudson.plugins.promoted_builds.PromotionProcess)7 InheritanceProjectsPair (hudson.plugins.promoted_builds.inheritance.helpers.InheritanceProjectsPair)7 Test (org.junit.Test)7 InheritanceBuild (hudson.plugins.project_inheritance.projects.InheritanceBuild)6 PromotedBuildAction (hudson.plugins.promoted_builds.PromotedBuildAction)6 Promotion (hudson.plugins.promoted_builds.Promotion)4 SelfPromotionCondition (hudson.plugins.promoted_builds.conditions.SelfPromotionCondition)4 StringParameterDefinition (hudson.model.StringParameterDefinition)3 Descriptor (hudson.model.Descriptor)2 ManualCondition (hudson.plugins.promoted_builds.conditions.ManualCondition)2 ManualApproval (hudson.plugins.promoted_builds.conditions.ManualCondition.ManualApproval)2 Bug (org.jvnet.hudson.test.Bug)2 HtmlElement (com.gargoylesoftware.htmlunit.html.HtmlElement)1 HtmlForm (com.gargoylesoftware.htmlunit.html.HtmlForm)1 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)1 ParameterDefinition (hudson.model.ParameterDefinition)1 ParameterValue (hudson.model.ParameterValue)1 ParametersAction (hudson.model.ParametersAction)1 ParametersDefinitionProperty (hudson.model.ParametersDefinitionProperty)1