use of hudson.model.FreeStyleBuild in project promoted-builds-plugin by jenkinsci.
the class PromotedBuildActionTest method testDeletedPromotionProcess.
public void testDeletedPromotionProcess() throws Exception {
FreeStyleProject p = createFreeStyleProject();
JobPropertyImpl base = new JobPropertyImpl(p);
p.addProperty(base);
PromotionProcess foo = base.addProcess("foo");
// promote a build
FreeStyleBuild b1 = assertBuildStatusSuccess(p.scheduleBuild2(0));
foo.promote(b1, new UserCause(), new ManualPromotionBadge());
// now delete the promotion process
p.removeProperty(base);
p.addProperty(base = new JobPropertyImpl(p));
assertTrue(base.getActiveItems().isEmpty());
// make sure that the page renders OK without any error
HtmlPage page = createWebClient().getPage(p);
List<?> candidates = page.getByXPath("//IMG");
for (Object candidate : candidates) {
if (!(candidate instanceof HtmlImage)) {
continue;
}
HtmlImage img = (HtmlImage) candidate;
try {
img.getHeight();
} catch (IOException e) {
throw new IOException2("Failed to load " + img.getSrcAttribute(), e);
}
}
}
use of hudson.model.FreeStyleBuild in project promoted-builds-plugin by jenkinsci.
the class PromotionEnvironmentVariablesTest method shouldSetJobAndJobFullNames.
@Test
public void shouldSetJobAndJobFullNames() throws Descriptor.FormException, IOException, InterruptedException, ExecutionException, 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();
promotionProcess.conditions.add(new ManualCondition());
Action approvalAction = new ManualCondition.ManualApproval(promotionProcess.getName(), new ArrayList<ParameterValue>());
// Act
FreeStyleBuild build = project.scheduleBuild2(0).get();
build.setDisplayName("1234");
build.addAction(approvalAction);
build.save();
Promotion promotion = promotionProcess.considerPromotion2(build).get();
EnvVars env = promotion.getEnvironment(TaskListener.NULL);
// Assert
assertEquals("Folder/Project", env.get("PROMOTED_JOB_FULL_NAME"));
assertEquals("Project", env.get("PROMOTED_JOB_NAME"));
assertEquals("Foobar", env.get("PROMOTED_USER_NAME"));
assertEquals("foo", env.get("PROMOTED_USER_ID"));
assertEquals("1234", env.get("PROMOTED_DISPLAY_NAME"));
project.delete();
parent.delete();
}
use of hudson.model.FreeStyleBuild 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.FreeStyleBuild 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());
}
use of hudson.model.FreeStyleBuild in project promoted-builds-plugin by jenkinsci.
the class GroovyConditionTest method testBinding.
@Test
public void testBinding() throws Exception {
FreeStyleProject p = j.createFreeStyleProject();
final JobPropertyImpl property = new JobPropertyImpl(p);
final PromotionProcess promotionProcess = property.addProcess("testPromotion");
promotionProcess.conditions.add(new GroovyCondition(new SecureGroovyScript("promotionProcess instanceof hudson.plugins.promoted_builds.PromotionProcess && " + "build instanceof hudson.model.AbstractBuild && " + "jenkins instanceof jenkins.model.Jenkins", false, null), "", ""));
p = j.configRoundtrip(p);
final FreeStyleBuild build = j.buildAndAssertSuccess(p);
Assert.assertNotNull("Promotion was expected", promotionProcess.isMet(build));
}
Aggregations