code: public AbstractProject<?,?> getRootProject() {
          if (this instanceof TopLevelItem) {
              return this;
          } else {
              ItemGroup p = this.getParent();
              if (p instanceof AbstractProject)
                  return ((AbstractProject) p).getRootProject();
              return this;
          }
      }
docs: Gets the nearest ancestor {@link TopLevelItem} that's also an {@link AbstractProject}.
  
  <p>
  Some projects (such as matrix projects, Maven projects, or promotion processes) form a tree of jobs
  that acts as a single unit. This method can be used to find the top most dominating job that
  covers such a tree.
  
  @return never null.
  @see AbstractBuild#getRootBuild()