code: protected int getNumFailures(Run<?, ?> build) {
          AbstractTestResultAction a = build.getAction(AbstractTestResultAction.class);
          if (a instanceof AggregatedTestResultAction) {
              int result = 0;
              AggregatedTestResultAction action = (AggregatedTestResultAction) a;
              for (ChildReport cr : action.getChildReports()) {
                  if (cr == null || cr.child == null || cr.child.getParent() == null) {
                      continue;
                  }
                  if (cr.child.getParent().equals(build.getParent())) {
                      if (cr.result instanceof TestResult) {
                          TestResult tr = (TestResult) cr.result;
                          result += tr.getFailCount();
                      }
                  }
              }
  
              if (result == 0 && action.getFailCount() > 0) {
                  result = action.getFailCount();
              }
              return result;
          }
          return a.getFailCount();
      }
docs: Determine the number of direct failures in the given build. If it
  aggregates downstream results, ignore contributed failures. This is
  because at the time this trigger runs, the current build's aggregated
  results aren't available yet, but those of the previous build may be.
  
  @param build The project run to get the number of test failures for.
  @return The number of test failures for the Run