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

job.allBuilds points to wrong URL when called from a job inside a folderJob

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Critical Critical
    • java-client-api
    • None

      When a job is residing in a folderJob then the API url to the job in job.allBuilds() points to /job/SIMPLE_JOB_NAME/api/json which causes a 404. Instead the job.allBuilds() should point to /job/FOLDER_JOB_NAME/job/SIMPLE_JOB_NAME/api/json.

      Code: JobWithDetails#127

      Fix:

      private String getJobPath() {
         String[] nameParts = this.getFullName().split("
      /");
         for(int i=0;i<nameParts.length;i++)

      {       nameParts[i] = EncodingUtils.encode(nameParts[i]);    }

         return "/job/" + String.join("/job/",nameParts);
      }

      public List<Build> getAllBuilds() throws IOException {
         String path = getJobPath();
         try {

            List<Build> builds = client.get(path + "?tree=allBuilds[number[*],url[*],queueId[*]]", AllBuilds.class).getAllBuilds();

            if (builds == null)

      {           return Collections.emptyList();       }

      else {
               return transform(builds, new Function<Build, Build>() {
                  @Override
                  public Build apply(Build from)

      {                return buildWithClient(from);            }

              });
            }
         } catch (HttpResponseException e) {
                    // TODO: Thinks about a better handling if the job does not exist?
               if (e.getStatusCode() == HttpStatus.SC_NOT_FOUND)

      {             // TODO: Check this if this is necessary or a good idea?            return null;         }

              throw e;
         }
      }

            khmarbaise Karl-Heinz Marbaise
            nlindberg Niclas Lindberg
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: