use of hudson.model.FreeStyleProject in project promoted-builds-plugin by jenkinsci.
the class PromotionProcessTest method testIsVisibleByDefault.
public void testIsVisibleByDefault() throws Exception {
FreeStyleProject project = createFreeStyleProject("project");
JobPropertyImpl jobProperty = new JobPropertyImpl(project);
project.addProperty(jobProperty);
PromotionProcess promotionProcess = jobProperty.addProcess("Promotion");
assertTrue(promotionProcess.isVisible());
}
use of hudson.model.FreeStyleProject in project promoted-builds-plugin by jenkinsci.
the class PromotionProcessTest method test1.
public void test1() throws Exception {
FreeStyleProject up = createFreeStyleProject("up");
FreeStyleProject down = createFreeStyleProject();
List<Recorder> recorders = Arrays.asList(new ArtifactArchiver("a.jar", null, false), new Fingerprinter("", true));
// upstream job
up.getBuildersList().add(new Shell("date > a.jar"));
up.getPublishersList().replaceBy(recorders);
// promote if the downstream passes
JobPropertyImpl promotion = new JobPropertyImpl(up);
up.addProperty(promotion);
PromotionProcess proc = promotion.addProcess("promo");
proc.conditions.add(new DownstreamPassCondition(down.getName()));
// this is the test job
String baseUrl = new WebClient().getContextPath() + "job/up/lastSuccessfulBuild";
down.getBuildersList().add(new Shell("wget -N " + baseUrl + "/artifact/a.jar \\\n" + " || curl " + baseUrl + "/artifact/a.jar > a.jar\n" + // expr exits with non-zero status if result is zero
"expr $BUILD_NUMBER % 2 - 1\n"));
down.getPublishersList().replaceBy(recorders);
// fire ItemListeners, this includes ArtifactArchiver,Migrator to make this test compatible with jenkins 1.575+
fireItemListeners();
// not yet promoted while the downstream is failing
FreeStyleBuild up1 = assertBuildStatusSuccess(up.scheduleBuild2(0).get());
assertBuildStatus(Result.FAILURE, down.scheduleBuild2(0).get());
// give it a time to not promote
Thread.sleep(1000);
assertEquals(0, proc.getBuilds().size());
// a successful downstream build promotes upstream
assertBuildStatusSuccess(down.scheduleBuild2(0).get());
// give it a time to promote
Thread.sleep(1000);
assertEquals(1, proc.getBuilds().size());
{
// verify that it promoted the right stuff
Promotion pb = proc.getBuilds().get(0);
assertSame(pb.getTarget(), up1);
PromotedBuildAction badge = (PromotedBuildAction) up1.getBadgeActions().get(0);
assertTrue(badge.contains(proc));
}
// make sure the UI persists the setup
configRoundtrip(up);
}
use of hudson.model.FreeStyleProject in project promoted-builds-plugin by jenkinsci.
the class RemoteApiTest method create.
@Test
public void create() throws Exception {
FreeStyleProject p = r.createFreeStyleProject("p");
JobPropertyImpl promotion = new JobPropertyImpl(p);
p.addProperty(promotion);
assertEquals(0, promotion.getItems().size());
assertEquals(0, promotion.getActiveItems().size());
JenkinsRule.WebClient wc = r.createWebClient();
WebRequest req = new WebRequest(new URL(wc.createCrumbedUrl("job/p/promotion/createProcess") + "&name=promo"), HttpMethod.POST);
req.setEncodingType(null);
req.setRequestBody("<hudson.plugins.promoted__builds.PromotionProcess><conditions><hudson.plugins.promoted__builds.conditions.SelfPromotionCondition><evenIfUnstable>true</evenIfUnstable></hudson.plugins.promoted__builds.conditions.SelfPromotionCondition></conditions></hudson.plugins.promoted__builds.PromotionProcess>");
wc.getPage(req);
assertEquals(1, promotion.getItems().size());
assertEquals("not yet in use", 0, promotion.getActiveItems().size());
PromotionProcess proc = promotion.getItem("promo");
assertNotNull(proc);
assertTrue(proc.conditions.get(SelfPromotionCondition.class).isEvenIfUnstable());
}
use of hudson.model.FreeStyleProject 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());
}
use of hudson.model.FreeStyleProject in project promoted-builds-plugin by jenkinsci.
the class DownstreamPassConditionTest method shouldEvaluateUpstreamRecursively.
@Test
@Bug(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());
}
Aggregations