private static String buildAndRun(
      Path projectRoot, String imageReference, String pomXml, boolean buildTwice)
      throws VerificationException, IOException, InterruptedException, DigestException {
    build(projectRoot, imageReference, pomXml, buildTwice).verifyErrorFreeLog();

    String output = pullAndRunBuiltImage(imageReference);

    try {
      // Test pulling/running using image digest
      String digest = readDigestFile(projectRoot.resolve("target/jib-image.digest"));
      String imageReferenceWithDigest =
          ImageReference.parse(imageReference).withQualifier(digest).toString();
      assertThat(pullAndRunBuiltImage(imageReferenceWithDigest)).isEqualTo(output);

      // Test running using image id
      String id = readDigestFile(projectRoot.resolve("target/jib-image.id"));
      assertThat(id).isNotEqualTo(digest);
      assertThat(new Command("docker", "run", "--rm", id).run()).isEqualTo(output);

    } catch (InvalidImageReferenceException ex) {
      throw new AssertionError("error replacing tag with digest", ex);
    }

    return output;
  }
Builds with {@code jib:build} on a project at {@code projectRoot} pushing to {@code
imageReference} and run the image after pulling it.
jib-maven-plugin/src/integration-test/java/com/google/cloud/tools/jib/maven/BuildImageMojoIntegrationTest.java