code: public @Nullable String getRootUrl() throws IllegalStateException {
          final JenkinsLocationConfiguration config = JenkinsLocationConfiguration.get();
          if (config == null) {
              // Try to get standard message if possible
              final Jenkins j = Jenkins.getInstance();
              throw new IllegalStateException("Jenkins instance " + j + " has been successfully initialized, but JenkinsLocationConfiguration is undefined.");
          }
          String url = config.getUrl();
          if(url!=null) {
              return Util.ensureEndsWith(url,"/");
          }
          StaplerRequest req = Stapler.getCurrentRequest();
          if(req!=null)
              return getRootUrlFromRequest();
          return null;
      }
docs: Gets the absolute URL of Jenkins, such as {@code http://localhost/jenkins/}.
  
  <p>
  This method first tries to use the manually configured value, then
  fall back to {@link #getRootUrlFromRequest}.
  It is done in this order so that it can work correctly even in the face
  of a reverse proxy.
  
  @return {@code null} if this parameter is not configured by the user and the calling thread is not in an HTTP request;
  otherwise the returned URL will always have the trailing {@code /}
  @throws IllegalStateException {@link JenkinsLocationConfiguration} cannot be retrieved.
  Jenkins instance may be not ready, or there is an extension loading glitch.
  @since 1.66
  @see <a href="https://wiki.jenkins-ci.org/display/JENKINS/Hyperlinks+in+HTML">Hyperlinks in HTML</a>