use of hudson.plugins.promoted_builds.Promotion 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));
}
use of hudson.plugins.promoted_builds.Promotion 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));
}
use of hudson.plugins.promoted_builds.Promotion 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());
}
use of hudson.plugins.promoted_builds.Promotion in project promoted-builds-plugin by jenkinsci.
the class ManualConditionBug22005 method testPromotionProcess.
public void testPromotionProcess() throws Exception {
FreeStyleProject p = createFreeStyleProject();
ExtensionList<Descriptor> list = hudson.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 = assertBuildStatusSuccess(p.scheduleBuild2(0));
Promotion p0b1 = assertBuildStatusSuccess(prom0Condition.approve(b1, prom0));
assertEquals(2, p0b1.getParameterValues().size());
assertEquals(2, p0b1.getParameterDefinitionsWithValue().size());
Promotion p1b1 = assertBuildStatusSuccess(prom1Condition.approve(b1, prom1));
assertEquals(2, p1b1.getParameterValues().size());
assertEquals(2, p1b1.getParameterDefinitionsWithValue().size());
Promotion p2b1 = 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());
}
}
use of hudson.plugins.promoted_builds.Promotion in project promoted-builds-plugin by jenkinsci.
the class SelfPromotionTest method testUnstable.
public void testUnstable() throws Exception {
FreeStyleProject p = 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
configRoundtrip(p);
// rebind
promotion = p.getProperty(JobPropertyImpl.class);
promo1 = promotion.getItem("promo1");
promo2 = promotion.getItem("promo2");
p.getBuildersList().add(unstableBuilder());
FreeStyleBuild b = 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.getTarget(), b);
PromotedBuildAction badge = (PromotedBuildAction) b.getBadgeActions().get(0);
assertFalse(badge.contains(promo1));
assertTrue(badge.contains(promo2));
}
Aggregations