/**
  * Determines whether any of the upstream project are either building or in the queue.
  *
  * <p>This means eventually there will be an automatic triggering of the given project (provided
  * that all builds went smoothly.)
  *
  * @param downstreamProject The AbstractProject we want to build.
  * @param excludeProject An AbstractProject to exclude - if we see this in the transitive
  *     dependencies, we're not going to bother checking to see if it's building. For example,
  *     pass the current parent project to be sure that it will be ignored when looking for
  *     building dependencies.
  * @return True if any upstream projects are building or in queue, false otherwise.
  */
 @SuppressWarnings("rawtypes")
 private boolean areUpstreamsBuilding(
     AbstractProject<?, ?> downstreamProject, AbstractProject<?, ?> excludeProject) {
   DependencyGraph graph = Jenkins.getInstance().getDependencyGraph();
   Set<AbstractProject> tups = graph.getTransitiveUpstream(downstreamProject);
   for (AbstractProject tup : tups) {
     if (tup != excludeProject && (tup.isBuilding() || tup.isInQueue())) return true;
   }
   return false;
 }
  @Override
  public boolean shouldSchedule(Task p, List<Action> actions) {
    if (p instanceof AbstractProject) {
      if (((AbstractProject) p).getProperty(SkipWhenUpstreamTriggeredJobProperty.class) != null) {

        // If any upstream projects are currently queued or building, skip scheduling
        Set<AbstractProject> upstreamProjects =
            ((AbstractProject) p).getTransitiveUpstreamProjects();
        for (AbstractProject upstreamProject : upstreamProjects) {
          if (upstreamProject.isBuilding()) {
            return false;
          }
          if (upstreamProject.isInQueue()) {
            return false;
          }
        }
      }
    }
    return true;
  }