Search in sources :

Example 6 with PromotionProcess

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

the class ManualConditionBug22005 method testPromotionProcess.

@Test
public void testPromotionProcess() 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 prom0 = createPromotionProcess(base, "PROM0");
    ManualCondition prom0Condition = prom0.conditions.get(ManualCondition.class);
    PromotionProcess prom1 = createPromotionProcess(base, "PROM1");
    ManualCondition prom1Condition = prom1.conditions.get(ManualCondition.class);
    PromotionProcess prom2 = createPromotionProcess(base, "PROM2");
    ManualCondition prom2Condition = prom2.conditions.get(ManualCondition.class);
    FreeStyleBuild b1 = j.assertBuildStatusSuccess(p.scheduleBuild2(0));
    Promotion p0b1 = j.assertBuildStatusSuccess(prom0Condition.approve(b1, prom0));
    assertEquals(2, p0b1.getParameterValues().size());
    assertEquals(2, p0b1.getParameterDefinitionsWithValue().size());
    Promotion p1b1 = j.assertBuildStatusSuccess(prom1Condition.approve(b1, prom1));
    assertEquals(2, p1b1.getParameterValues().size());
    assertEquals(2, p1b1.getParameterDefinitionsWithValue().size());
    Promotion p2b1 = j.assertBuildStatusSuccess(prom2Condition.approve(b1, prom2));
    assertEquals(2, p2b1.getParameterValues().size());
    assertEquals(2, p2b1.getParameterDefinitionsWithValue().size());
    List<ManualApproval> approvals = b1.getActions(ManualApproval.class);
    assertEquals(3, approvals.size());
    PromotedBuildAction promBuildAction = b1.getAction(PromotedBuildAction.class);
    List<Status> statuses = promBuildAction.getPromotions();
    assertEquals(3, statuses.size());
    for (Status status : statuses) {
        Promotion lastBuild = status.getLast();
        List<ParameterDefinition> lastBuildParameters = lastBuild.getParameterDefinitionsWithValue();
        assertEquals(2, lastBuildParameters.size());
    }
}
Also used : Status(hudson.plugins.promoted_builds.Status) ManualApproval(hudson.plugins.promoted_builds.conditions.ManualCondition.ManualApproval) FreeStyleBuild(hudson.model.FreeStyleBuild) PromotedBuildAction(hudson.plugins.promoted_builds.PromotedBuildAction) FreeStyleProject(hudson.model.FreeStyleProject) JobPropertyImpl(hudson.plugins.promoted_builds.JobPropertyImpl) Promotion(hudson.plugins.promoted_builds.Promotion) PromotionProcess(hudson.plugins.promoted_builds.PromotionProcess) Descriptor(hudson.model.Descriptor) ParameterDefinition(hudson.model.ParameterDefinition) StringParameterDefinition(hudson.model.StringParameterDefinition) Test(org.junit.Test)

Example 7 with PromotionProcess

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

the class SelfPromotionTest method testUnstable.

@Test
public void testUnstable() throws Exception {
    FreeStyleProject p = j.createFreeStyleProject();
    // promote if the downstream passes
    JobPropertyImpl promotion = new JobPropertyImpl(p);
    p.addProperty(promotion);
    PromotionProcess promo1 = promotion.addProcess("promo1");
    promo1.conditions.add(new SelfPromotionCondition(false));
    PromotionProcess promo2 = promotion.addProcess("promo2");
    promo2.conditions.add(new SelfPromotionCondition(true));
    // ensure that the data survives the roundtrip
    j.configRoundtrip(p);
    // rebind
    promotion = p.getProperty(JobPropertyImpl.class);
    promo1 = promotion.getItem("promo1");
    promo2 = promotion.getItem("promo2");
    p.getBuildersList().add(unstableBuilder());
    FreeStyleBuild b = j.assertBuildStatus(Result.UNSTABLE, p.scheduleBuild2(0).get());
    // internally, the promotion is still an asynchronous process. It just happens
    // right away after the build is complete.
    Thread.sleep(1000);
    // verify that only one promotions happened
    assertTrue(promo1.getBuilds().isEmpty());
    Promotion pb = promo2.getBuilds().get(0);
    assertSame(pb.getTargetBuildOrFail(), b);
    PromotedBuildAction badge = (PromotedBuildAction) b.getBadgeActions().get(0);
    assertFalse(badge.contains(promo1));
    assertTrue(badge.contains(promo2));
}
Also used : PromotionProcess(hudson.plugins.promoted_builds.PromotionProcess) FreeStyleBuild(hudson.model.FreeStyleBuild) PromotedBuildAction(hudson.plugins.promoted_builds.PromotedBuildAction) FreeStyleProject(hudson.model.FreeStyleProject) JobPropertyImpl(hudson.plugins.promoted_builds.JobPropertyImpl) Promotion(hudson.plugins.promoted_builds.Promotion) Test(org.junit.Test)

Example 8 with PromotionProcess

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

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

the class PromotedEnvVarTokenMacroTest method testEnvironmentVariableExpansion.

@Test
public void testEnvironmentVariableExpansion() throws Exception {
    // Assemble
    r.jenkins.setSecurityRealm(r.createDummySecurityRealm());
    User u = User.get("foo");
    u.setFullName("Foobar");
    SecurityContextHolder.getContext().setAuthentication(u.impersonate());
    MockFolder parent = r.createFolder("Folder");
    FreeStyleProject project = parent.createProject(FreeStyleProject.class, "Project");
    JobPropertyImpl promotionProperty = new JobPropertyImpl(project);
    PromotionProcess promotionProcess = promotionProperty.addProcess("promo");
    promotionProcess.conditions.clear();
    ManualCondition manualCondition = new ManualCondition();
    manualCondition.getParameterDefinitions().add(new StringParameterDefinition("PROMOTION_PARAM", "defaultValue"));
    promotionProcess.conditions.add(manualCondition);
    Action approvalAction = new ManualCondition.ManualApproval(promotionProcess.getName(), new LinkedList<ParameterValue>());
    TokenMacroExpressionRecorder recorder = new TokenMacroExpressionRecorder("${PROMOTION_ENV,var=\"PROMOTION_PARAM\"}");
    promotionProcess.getBuildSteps().add(recorder);
    // Act & promote
    FreeStyleBuild build = project.scheduleBuild2(0).get();
    build.addAction(approvalAction);
    build.save();
    Promotion promotion = promotionProcess.considerPromotion2(build, Arrays.asList((ParameterValue) new StringParameterValue("PROMOTION_PARAM", "FOO"))).get();
    // Check results
    EnvVars env = promotion.getEnvironment(TaskListener.NULL);
    assertEquals("The PROMOTION_PARAM variable has not been injected", "FOO", env.get("PROMOTION_PARAM"));
    assertEquals("The promotion variable value has not been resolved by the PROMOTION_PARAM macro", "FOO", recorder.getCaptured());
}
Also used : Action(hudson.model.Action) User(hudson.model.User) StringParameterDefinition(hudson.model.StringParameterDefinition) StringParameterValue(hudson.model.StringParameterValue) ParameterValue(hudson.model.ParameterValue) StringParameterValue(hudson.model.StringParameterValue) FreeStyleBuild(hudson.model.FreeStyleBuild) MockFolder(org.jvnet.hudson.test.MockFolder) FreeStyleProject(hudson.model.FreeStyleProject) JobPropertyImpl(hudson.plugins.promoted_builds.JobPropertyImpl) Promotion(hudson.plugins.promoted_builds.Promotion) ManualCondition(hudson.plugins.promoted_builds.conditions.ManualCondition) EnvVars(hudson.EnvVars) PromotionProcess(hudson.plugins.promoted_builds.PromotionProcess) Test(org.junit.Test)

Example 10 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)

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