code: public static @CheckForNull
      Run<?, ?> getPreviousRun(@Nonnull Run<?, ?> run, TaskListener listener) {
          Run<?, ?> previousRun = run.getPreviousBuild();
          if (previousRun != null && previousRun.isBuilding()) {
              listener.getLogger().println(Messages.ExtendedEmailPublisher__is_still_in_progress_ignoring_for_purpo(previousRun.getDisplayName()));
              return null;
          } else {
              return previousRun;
          }
      }
docs: Looks for a previous build, so long as that is in fact completed.
  Necessary since {@link #getRequiredMonitorService} does not wait for the
  previous build, so in the case of parallel-capable jobs, we need to
  behave sensibly when a later build actually finishes before an earlier
  one.
  
  @param run a run for which we may be sending mail
  @param listener a listener to which we may print warnings in case the
  actual previous build is still in progress
  @return the previous build, or null if that build is missing, or is still
  in progress