use of hudson.plugins.promoted_builds.conditions.DownstreamPassCondition 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.conditions.DownstreamPassCondition in project promoted-builds-plugin by jenkinsci.
the class ConfigurationRoundtripTest method testRoundtrip.
/**
* Configuration roundtrip test to detect data loss.
*/
@Test
public void testRoundtrip() throws Exception {
FreeStyleProject down = j.createFreeStyleProject();
FreeStyleProject p = j.createFreeStyleProject();
JobPropertyImpl pp = new JobPropertyImpl(p);
p.addProperty(pp);
PromotionProcess proc = pp.addProcess("test");
assertEquals(1, pp.getItems().size());
proc.conditions.add(new DownstreamPassCondition(down.getName()));
proc.getBuildSteps().add(new JavadocArchiver("somedir", true));
proc.getBuildWrappersList().add(new ConfigFileBuildWrapper(new ArrayList<ManagedFile>()));
proc.icon = "star-blue";
// round trip
JenkinsRule.WebClient wc = j.createWebClient();
submit(wc.getPage(p, "configure").getFormByName("config"));
// assert that the configuration is still intact
pp = p.getProperty(JobPropertyImpl.class);
assertEquals(1, pp.getItems().size());
proc = pp.getItem("test");
assertEquals(1, proc.conditions.toList().size());
DownstreamPassCondition dcp = proc.conditions.get(DownstreamPassCondition.class);
assertEquals(dcp.getJobs(), down.getName());
assertEquals(1, proc.getBuildSteps().size());
JavadocArchiver ja = (JavadocArchiver) proc.getBuildSteps().get(0);
assertEquals("somedir", ja.getJavadocDir());
assertTrue(ja.isKeepAll());
ConfigFileBuildWrapper buildWrapper = (ConfigFileBuildWrapper) proc.getBuildWrappersList().get(0);
assertNotNull(buildWrapper);
assertEquals("star-blue", proc.icon);
}
use of hudson.plugins.promoted_builds.conditions.DownstreamPassCondition in project promoted-builds-plugin by jenkinsci.
the class PromotionProcessTest method test1.
@Test
public void test1() throws Exception {
FreeStyleProject up = j.createFreeStyleProject("up");
FreeStyleProject down = j.createFreeStyleProject();
Recorder r1 = new ArtifactArchiver("a.jar", null, false);
Recorder r2 = new Fingerprinter("", true);
List<Recorder> recorders = Arrays.asList(r1, r2);
// upstream job
up.getBuildersList().add(Functions.isWindows() ? new BatchFile("date /t > a.jar") : 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 = j.createWebClient().getContextPath() + "job/up/lastSuccessfulBuild";
String artifactUrl = baseUrl + "/artifact/a.jar";
down.getBuildersList().add(Functions.isWindows() ? new BatchFile("powershell -command \"Invoke-WebRequest " + artifactUrl + " -OutFile a.jar\"\r\n" + "set /a \"exitCode=BUILD_NUMBER%%2\"\r\n" + "exit /b %exitCode%\r\n") : new Shell("wget -N " + artifactUrl + " \\\n" + " || curl " + artifactUrl + " > 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 = j.assertBuildStatusSuccess(up.scheduleBuild2(0).get());
j.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
j.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.getTargetBuildOrFail(), up1);
PromotedBuildAction badge = (PromotedBuildAction) up1.getBadgeActions().get(0);
assertTrue(badge.contains(proc));
}
// make sure the UI persists the setup
j.configRoundtrip(up);
}
use of hudson.plugins.promoted_builds.conditions.DownstreamPassCondition in project promoted-builds-plugin by jenkinsci.
the class ConfigurationDoCheckTest method testCheckInvalidProcessName.
@Issue("JENKINS-7972")
@Test
public void testCheckInvalidProcessName() throws Exception {
FreeStyleProject down = j.createFreeStyleProject();
FreeStyleProject p = j.createFreeStyleProject();
JobPropertyImpl pp = new JobPropertyImpl(p);
p.addProperty(pp);
PromotionProcess proc = pp.addProcess("test/");
assertEquals(1, pp.getItems().size());
proc.conditions.add(new DownstreamPassCondition(down.getName()));
proc.getBuildSteps().add(new JavadocArchiver("somedir", true));
proc.icon = "star-blue";
JenkinsRule.WebClient client = j.createWebClient();
client.getOptions().setThrowExceptionOnFailingStatusCode(false);
HtmlPage page = (HtmlPage) submit(client.getPage(p, "configure").getFormByName("config"));
assertTrue(page.getVisibleText().contains("unsafe character"));
}
use of hudson.plugins.promoted_builds.conditions.DownstreamPassCondition in project promoted-builds-plugin by jenkinsci.
the class ConfigurationDoCheckTest method testCheckProcessNameRequired.
@Issue("JENKINS-7972")
@Test
public void testCheckProcessNameRequired() throws Exception {
FreeStyleProject down = j.createFreeStyleProject();
FreeStyleProject p = j.createFreeStyleProject();
JobPropertyImpl pp = new JobPropertyImpl(p);
p.addProperty(pp);
PromotionProcess proc = pp.addProcess("");
assertEquals(1, pp.getItems().size());
proc.conditions.add(new DownstreamPassCondition(down.getName()));
proc.getBuildSteps().add(new JavadocArchiver("somedir", true));
proc.icon = "star-blue";
JenkinsRule.WebClient client = j.createWebClient();
client.getOptions().setThrowExceptionOnFailingStatusCode(false);
HtmlPage page = (HtmlPage) submit(client.getPage(p, "configure").getFormByName("config"));
assertTrue(page.getVisibleText().contains("No name is specified"));
}
Aggregations