use of hudson.plugins.promoted_builds.PromotedBuildAction in project promoted-builds-plugin by jenkinsci.
the class UpstreamPromotionCondition method isMet.
@Override
public PromotionBadge isMet(PromotionProcess promotionProcess, AbstractBuild<?, ?> build) {
Badge badge = new Badge();
Set<String> requiredPromotions = getRequiredPromotionNamesAsSet();
if (requiredPromotions.isEmpty()) {
return badge;
}
PromotedBuildAction pba = build.getAction(PromotedBuildAction.class);
if (pba == null) {
return null;
}
for (Status status : pba.getPromotions()) {
if (status.isPromotionSuccessful()) {
requiredPromotions.remove(status.getName());
badge.add(status.getName());
// short circuit for loop if
if (requiredPromotions.isEmpty())
break;
}
}
return requiredPromotions.isEmpty() ? badge : null;
}
use of hudson.plugins.promoted_builds.PromotedBuildAction 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());
}
use of hudson.plugins.promoted_builds.PromotedBuildAction 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());
}
use of hudson.plugins.promoted_builds.PromotedBuildAction 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());
}
use of hudson.plugins.promoted_builds.PromotedBuildAction 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));
}
Aggregations