@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"));
 }
  private Slave create(String host, Jenkins j) {
    // Just to make sure the dumb slave is set up properly, we should seed it
    // with a FS root and executors
    final DumbSlave s = j.slaves.create(DumbSlave.class);

    s.find(by.input("_.host")).sendKeys(host);

    sleep(25);

    final Select cId = new Select(s.find(by.input("_.credentialsId")));
    final String credentialName = String.format("%s (%s)", machine.getUser(), fingerprint);
    s.waitForCond(
        new Callable<Object>() {
          @Override
          public Object call() throws Exception {
            List<WebElement> options = cId.getOptions();
            for (WebElement e : options) {
              if (credentialName.equals(e.getText())) return true;
            }
            return false;
          }
        });
    cId.selectByVisibleText(credentialName);
    s.setExecutors(1);

    s.save();
    return s;
  }