@WithPlugins({"[email protected]", "[email protected]"}) @Test public void linearFlow() throws Exception { MavenInstallation.installMaven(jenkins, "M3", "3.1.0"); final DumbSlave slave = (DumbSlave) slaveController.install(jenkins).get(); slave.configure( new Callable<Void>() { @Override public Void call() throws Exception { slave.labels.set("remote"); return null; } }); WorkflowJob job = jenkins.jobs.create(WorkflowJob.class); job.script.set( "node('remote') {\n" + " git url: 'https://github.com/jglick/simple-maven-project-with-tests.git'\n" + " def v = version()\n" + " if (v) {\n" + " echo \"Building version ${v}\"\n" + " }\n" + " def mvnHome = tool 'M3'\n" + " sh \"${mvnHome}/bin/mvn -B -Dmaven.test.failure.ignore verify\"\n" + " input 'Ready to go?'\n" + " step([$class: 'ArtifactArchiver', artifacts: '**/target/*.jar', fingerprint: true])\n" + " step([$class: 'JUnitResultArchiver', testResults: '**/target/surefire-reports/TEST-*.xml'])\n" + "}\n" + "def version() {\n" + " def matcher = readFile('pom.xml') =~ '<version>(.+)</version>'\n" + " matcher ? matcher[0][1] : null\n" + "}"); job.sandbox.check(); job.save(); final Build build = job.startBuild(); waitFor() .until( new Callable<Boolean>() { @Override public Boolean call() throws Exception { return build.getConsole().contains("Ready to go?"); } }); build.shouldContainsConsoleOutput("Building version 1.0-SNAPSHOT"); jenkins.restart(); visit(build.getConsoleUrl()); clickLink("Proceed"); assertTrue( build.isSuccess() || build .isUnstable()); // tests in this project are currently designed to fail at random, // so either is OK new Artifact(build, "target/simple-maven-project-with-tests-1.0-SNAPSHOT.jar") .assertThatExists(true); build.open(); clickLink("Test Result"); assertThat(driver, hasContent("All Tests")); }
@Test public void autoinstall_maven2_for_freestyle_job() { installMaven(jenkins, "maven_2.2.1", "2.2.1"); FreeStyleJob job = jenkins.jobs.create(); job.configure(); MavenBuildStep step = job.addBuildStep(MavenBuildStep.class); step.version.select("maven_2.2.1"); step.targets.set("-version"); job.save(); job.startBuild() .shouldSucceed() .shouldContainsConsoleOutput("Apache Maven 2.2.1") .shouldContainsConsoleOutput( "Unpacking http://archive.apache.org/dist/maven/binaries/apache-maven-2.2.1-bin.zip"); }