use of hudson.tasks.BatchFile in project promoted-builds-plugin by jenkinsci.
the class PromotionBuildWrapperTest method testApplyBuildWrapper.
@Test
public void testApplyBuildWrapper() throws Exception {
FreeStyleProject project = j.createFreeStyleProject();
JobPropertyImpl jobProperty = new JobPropertyImpl(project);
project.addProperty(jobProperty);
PromotionProcess promotion = jobProperty.addProcess("test");
TestBuildWrapper buildWrapper = new TestBuildWrapper();
promotion.getBuildWrappersList().add(buildWrapper);
promotion.getBuildSteps().add(Functions.isWindows() ? new BatchFile("echo Hello, world") : new Shell("echo Hello, world"));
// trigger build
FreeStyleBuild build = j.assertBuildStatusSuccess(project.scheduleBuild2(0).get());
// trigger promotion
promotion.promote(build, new Cause.UserIdCause(), new ManualPromotionBadge());
Thread.sleep(1000);
assertEquals(1, promotion.getBuilds().size());
Promotion promotionBuild = promotion.getBuilds().get(0);
assertSame(promotionBuild.getTargetBuildOrFail(), build);
assertEquals(Result.SUCCESS, buildWrapper.buildResultInTearDown);
}
use of hudson.tasks.BatchFile in project promoted-builds-plugin by jenkinsci.
the class PromotionTest method testPromotionLog.
@Test
@Issue("JENKINS-59600")
public void testPromotionLog() throws Exception {
FreeStyleProject p = r.createFreeStyleProject("proj1");
JobPropertyImpl promotion = new JobPropertyImpl(p);
p.addProperty(promotion);
PromotionProcess promo1 = promotion.addProcess("promo1");
promo1.getBuildSteps().add(Functions.isWindows() ? new BatchFile("echo ABCDEFGH") : new Shell("echo ABCDEFGH"));
promo1.conditions.add(new SelfPromotionCondition(false));
FreeStyleBuild b = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
// internally, the promotion is still an asynchronous process. It just happens
// right away after the build is complete.
Thread.sleep(1000);
Promotion pb = promo1.getBuilds().getLastBuild();
assertSame(pb.getTargetBuildOrFail(), b);
JenkinsRule.WebClient wc = r.createWebClient();
// spot-check that promotion itself is accessible
final Page page = wc.goTo(pb.getUrl() + "consoleText", "text/plain");
assertThat(pb.getUrl() + "/consoleText + is not a promotion log", page.getWebResponse().getContentAsString(), CoreMatchers.containsString("ABCDEFGH"));
}
use of hudson.tasks.BatchFile 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.tasks.BatchFile in project promoted-builds-plugin by jenkinsci.
the class PromotionProcessTest method testPromotionWithoutFingerprint.
/**
* Tests a promotion induced by the pseudo upstream/downstream cause relationship
*/
@Test
public void testPromotionWithoutFingerprint() throws Exception {
FreeStyleProject up = j.createFreeStyleProject("up");
FreeStyleProject down = j.createFreeStyleProject();
// 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()));
// trigger downstream automatically to create relationship
up.getPublishersList().add(new BuildTrigger(down.getName(), Result.SUCCESS));
j.jenkins.rebuildDependencyGraph();
// this is the downstream job
down.getBuildersList().add(Functions.isWindows() ? new BatchFile("set /a \"exitCode=BUILD_NUMBER%%2\"\r\n" + "exit /b %exitCode%\r\n") : // expr exits with non-zero status if result is zero
new Shell("expr $BUILD_NUMBER % 2 - 1\n"));
// not yet promoted while the downstream is failing
FreeStyleBuild up1 = j.assertBuildStatusSuccess(up.scheduleBuild2(0).get());
waitForCompletion(down, 1);
assertEquals(0, proc.getBuilds().size());
// do it one more time and this time it should work
FreeStyleBuild up2 = j.assertBuildStatusSuccess(up.scheduleBuild2(0).get());
waitForCompletion(down, 2);
assertEquals(1, proc.getBuilds().size());
{
// verify that it promoted the right stuff
Promotion pb = proc.getBuilds().get(0);
assertSame(pb.getTargetBuildOrFail(), up2);
PromotedBuildAction badge = (PromotedBuildAction) up2.getBadgeActions().get(0);
assertTrue(badge.contains(proc));
}
}
Aggregations