Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-15948

Analyzer Icons aren't displayed if Jenkins isn't installed at root context.

    Details

      Description

      The paths to icons appears to assume that Jenkins has been installed at the root webapp context. If this isn't the case, the images are broken.

      For example, this is one such URL:

      http://[host]/plugin/build-failure-analyzer/images/16x16/information.png

      But because my jenkins url is http://[host]/jenkins, the above produces a 404.

        Issue Links

          Activity

          Hide
          f_ritaly FRANCOIS RITALY added a comment -

          I confirm that this issue still exists. My Jenkins is installed at "http://jenkins.mycorp.com/jenkins" and the plugin generates URLs with an extra "/jenkins" in the URL like http://jenkins.mycorp.com/jenkins/jenkins/plugin/build-failure-analyzer/images/16x16/information.png.

          I had a look to the plugin source and found that the issue was located in method PluginImpl.getFullImageUrl(String, String).

          Here's the initial method code.

              public static String getFullImageUrl(String size, String name) {
                  String url = Mailer.descriptor().getUrl();
                  if (url != null) {
                      String contextPath = "";
                      StaplerRequest currentRequest = Stapler.getCurrentRequest();
                      if (currentRequest != null) {
                          contextPath = currentRequest.getContextPath();
                      }
                      if (contextPath.startsWith("/")) {
                          contextPath = contextPath.substring(1);
                      }
                      return Hudson.getInstance().getRootUrl() + contextPath + getImageUrl(size, name);
                  }
                  return Hudson.getInstance().getRootUrlFromRequest() + getStaticImagesBase()
                          + "/" + size + "/" + name;
              }
          

          When I change the method into the following, the problem is fixed.

              public static String getFullImageUrl(String size, String name) {
                  String url = Mailer.descriptor().getUrl();
                  if (url != null) {
                      String contextPath = "";
                      StaplerRequest currentRequest = Stapler.getCurrentRequest();
                      if (currentRequest != null) {
                          contextPath = currentRequest.getContextPath();
                      }
                      if (contextPath.startsWith("/")) {
                          contextPath = contextPath.substring(1);
                      }
          
                      // return Hudson.getInstance().getRootUrl() + contextPath + getImageUrl(size, name);
                      return Hudson.getInstance().getRootUrl() + getImageUrl(size, name);
                  }
                  return Hudson.getInstance().getRootUrlFromRequest() + getStaticImagesBase()
                          + "/" + size + "/" + name;
              }
          

          However since the method doesn't use the contextPath variable any more, it can be simplified into this:

              public static String getFullImageUrl(String size, String name) {
                  return Hudson.getInstance().getRootUrl() + getImageUrl(size, name);
              }
          

          I must be missing something. Why do we need 2 return statements ? Are the use cases that justify to have 2 return statements ?

          Something else that I noticed during my tests with a fresh local Jenkins 1.537. In "Manage Jenkins" > "Configure System", there's a section "Jenkins Location" and a field "Jenkins URL". By default the "Jenkins URL" field is set to "http://localhost:8080/jenkins/".

          With the default value in the "Jenkins URL" field, the missing icon bug doesn't occur.

          When I changed the "Jenkins URL" field to "http://jenkins.mycorp.com/jenkins", the icons are missing.

          It seems that Jenkins recognizes "http://localhost:8080/jenkins/" as the default url and has a given behavior. When this URL is changed, the behavior changes.

          Show
          f_ritaly FRANCOIS RITALY added a comment - I confirm that this issue still exists. My Jenkins is installed at "http://jenkins.mycorp.com/jenkins" and the plugin generates URLs with an extra "/jenkins" in the URL like http://jenkins.mycorp.com/jenkins/jenkins/plugin/build-failure-analyzer/images/16x16/information.png . I had a look to the plugin source and found that the issue was located in method PluginImpl.getFullImageUrl(String, String). Here's the initial method code. public static String getFullImageUrl( String size, String name) { String url = Mailer.descriptor().getUrl(); if (url != null ) { String contextPath = ""; StaplerRequest currentRequest = Stapler.getCurrentRequest(); if (currentRequest != null ) { contextPath = currentRequest.getContextPath(); } if (contextPath.startsWith( "/" )) { contextPath = contextPath.substring(1); } return Hudson.getInstance().getRootUrl() + contextPath + getImageUrl(size, name); } return Hudson.getInstance().getRootUrlFromRequest() + getStaticImagesBase() + "/" + size + "/" + name; } When I change the method into the following, the problem is fixed. public static String getFullImageUrl( String size, String name) { String url = Mailer.descriptor().getUrl(); if (url != null ) { String contextPath = ""; StaplerRequest currentRequest = Stapler.getCurrentRequest(); if (currentRequest != null ) { contextPath = currentRequest.getContextPath(); } if (contextPath.startsWith( "/" )) { contextPath = contextPath.substring(1); } // return Hudson.getInstance().getRootUrl() + contextPath + getImageUrl(size, name); return Hudson.getInstance().getRootUrl() + getImageUrl(size, name); } return Hudson.getInstance().getRootUrlFromRequest() + getStaticImagesBase() + "/" + size + "/" + name; } However since the method doesn't use the contextPath variable any more, it can be simplified into this: public static String getFullImageUrl( String size, String name) { return Hudson.getInstance().getRootUrl() + getImageUrl(size, name); } I must be missing something. Why do we need 2 return statements ? Are the use cases that justify to have 2 return statements ? Something else that I noticed during my tests with a fresh local Jenkins 1.537. In "Manage Jenkins" > "Configure System", there's a section "Jenkins Location" and a field "Jenkins URL". By default the "Jenkins URL" field is set to "http://localhost:8080/jenkins/". With the default value in the "Jenkins URL" field, the missing icon bug doesn't occur. When I changed the "Jenkins URL" field to "http://jenkins.mycorp.com/jenkins", the icons are missing. It seems that Jenkins recognizes "http://localhost:8080/jenkins/" as the default url and has a given behavior. When this URL is changed, the behavior changes.
          Hide
          juliogonzalez Julio Gonzalez Gil added a comment - - edited
          Show
          juliogonzalez Julio Gonzalez Gil added a comment - - edited For me it's happening as well with 1.6.0 and Jenkins 1.537 If jenkins is located at http://jenkins.mycorp.com/jenkins , then some URL for images are written as http://jenkins.mycorp.com/jenkins/jenkins/plugin/build-failure-analyzer/images/* I'm having problems with http://jenkins.mycorp.com/jenkins/jenkins/plugin/build-failure-analyzer/images/48x48/information.png and http://jenkins.mycorp.com/jenkins/jenkins/plugin/build-failure-analyzer/images/16x16/information.png If Jenkins is installed at root folder ( http://jenkins.mycorp.com/ ) then the route is http://jenkins.mycorp.com//plugin/build-failure-analyzer/images/48x48/information.png (incorrect) but the image loads as one slash is ignored.
          Hide
          walterk82 Walter Kacynski added a comment -

          Is there a particular reason these this change is not progressing? For more information please see https://wiki.jenkins-ci.org/display/JENKINS/Hyperlinks+in+HTML

          Show
          walterk82 Walter Kacynski added a comment - Is there a particular reason these this change is not progressing? For more information please see https://wiki.jenkins-ci.org/display/JENKINS/Hyperlinks+in+HTML
          Hide
          andi_scharfstein Andi Scharfstein added a comment -

          Can confirm that this still is an issue.

          Show
          andi_scharfstein Andi Scharfstein added a comment - Can confirm that this still is an issue.
          Hide
          gitt gitt added a comment -

          Problem with "jenkins/jenkins" in the URL still exists in 1.10.0

          Show
          gitt gitt added a comment - Problem with "jenkins/jenkins" in the URL still exists in 1.10.0

            People

            • Assignee:
              t_westling Tomas Westling
              Reporter:
              prospero238 Keith Collison
            • Votes:
              12 Vote for this issue
              Watchers:
              18 Start watching this issue

              Dates

              • Created:
                Updated: