@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
  @Native("mvn")
  public void use_native_maven() {
    jenkins.configure();
    MavenInstallation maven = jenkins.getConfigPage().addTool(MavenInstallation.class);
    maven.name.set("native_maven");
    maven.useNative();
    jenkins.save();

    String expectedVersion = localMavenVersion();

    FreeStyleJob job = jenkins.jobs.create();
    job.configure();
    MavenBuildStep step = job.addBuildStep(MavenBuildStep.class);
    step.version.select("native_maven");
    step.targets.set("--version");
    job.save();

    Build build = job.startBuild().shouldSucceed();

    build.shouldContainsConsoleOutput(Pattern.quote(expectedVersion));
  }