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

REST api needed to get individual warnings values, not combined ones

    • Icon: New Feature New Feature
    • Resolution: Fixed
    • Icon: Minor Minor
    • warnings-plugin
    • None

      At the moment there is REST api warningsResult/ that shows the combined warnings.
      If the build counts gcc and lint warnings for example then it is impossible to know what each parsers value is since they get combined.

      PC-lint's url is warnings0Result/
      and
      GCC's url is warnings17Result/

      but there doesn't seem to be a way to find out what parsers was executed and what their values are beforehand. (without hardcoding and guessing urls)

      So my request is for a REST api to provide a list of
      names and urls

      e.g.
      [

      {"parserName":"GCC","url":"warnings17Result"}

      ,

      {"parserName":"PC-Lint","url":"warnings0Result"}

      ]

      using this i can then go and query each url

          [JENKINS-26113] REST api needed to get individual warnings values, not combined ones

          Morne Joubert created issue -

          Ulli Hafner added a comment -

          That should be feasible. Interested in providing a pull request?

          Ulli Hafner added a comment - That should be feasible. Interested in providing a pull request?

          Morne Joubert added a comment -

          sure, just point me to the relevant git location and java code to start and i will do some testing.

          Morne Joubert added a comment - sure, just point me to the relevant git location and java code to start and i will do some testing.

          Ulli Hafner added a comment - - edited

          I made all project actions of analysis-core ready for remote API. So you just need to add your code to https://github.com/jenkinsci/warnings-plugin/blob/master/src/main/java/hudson/plugins/warnings/AggregatedWarningsProjectAction.java.

          You can add elements using the @Exported annotation. The current result just returns the display name of the action (http://localhost:8080/job/[job-name]/warnings/api/xml):

          <aggregatedWarningsProjectAction>
            <displayName>Compiler Warnings</displayName>
            <lastFinishedBuild>
              <number>57</number>
              <url>http://localhost:8080/job/Freestyle/57/</url>
            </lastFinishedBuild>
          </aggregatedWarningsProjectAction>
          

          In that class you can read all project WarningProjectActions and return the IDs.

          Ulli Hafner added a comment - - edited I made all project actions of analysis-core ready for remote API. So you just need to add your code to https://github.com/jenkinsci/warnings-plugin/blob/master/src/main/java/hudson/plugins/warnings/AggregatedWarningsProjectAction.java . You can add elements using the @Exported annotation. The current result just returns the display name of the action ( http://localhost:8080/job/[job-name]/warnings/api/xml): <aggregatedWarningsProjectAction> <displayName>Compiler Warnings</displayName> <lastFinishedBuild> <number>57</number> <url>http://localhost:8080/job/Freestyle/57/</url> </lastFinishedBuild> </aggregatedWarningsProjectAction> In that class you can read all project WarningProjectActions and return the IDs.

          Ulli Hafner added a comment -

          BTW: Rather than returning the URLs you can also return the actual aggregated results? Wouldn't that be more comfortable?

          Ulli Hafner added a comment - BTW: Rather than returning the URLs you can also return the actual aggregated results? Wouldn't that be more comfortable?

          Morne Joubert added a comment -

          yes, that would be even better.
          I will pull the code and see if i can get something going

          Morne Joubert added a comment - yes, that would be even better. I will pull the code and see if i can get something going

          Morne Joubert added a comment -

          i can't seem to get the list of warnings actions.....

          I can see them in the debugger in the transientActions Vector but the values are protected

          Morne Joubert added a comment - i can't seem to get the list of warnings actions..... I can see them in the debugger in the transientActions Vector but the values are protected

          Ulli Hafner added a comment -

          Can't you use

          public <T extends Action> List<T> getActions(Class<T> type)
          

          with the build or job object? Just use WarningsResultAction.class as type.

          Ulli Hafner added a comment - Can't you use public <T extends Action> List<T> getActions( Class <T> type) with the build or job object? Just use WarningsResultAction.class as type.

          Morne Joubert added a comment - - edited

          I added the following in AggregatedWarningsProjectAction.java

          @Exported
              public List<WarningsResultAction> getWarningsResultAction() {
          
                  List<WarningsResultAction> projectActions;
                  // projectActions = this.getProject().getActions(WarningsResultAction.class);
                  // can't use project, its actions list is allways empty
          
                  // try getting the actions of the last build
                  projectActions = this.getLastFinishedBuild().getActions(WarningsResultAction.class);
          
                  return projectActions;
              }
          

          Inside WarningsResultAction.java i then added the exported and visibility fields

           @Exported(visibility = 2)
              @Override
              public String getUrlName() {
                  return WarningsDescriptor.getResultUrl(parserName);
              }
          
              /**
               * Returns the parser group this result belongs to.
               *
               * @return the parser group
               */
              @Exported(visibility = 2)
              public String getParser() {
                  return parserName;
              }
          
              @Exported(visibility = 2)
              @Override
              public String getDisplayName() {
                  return ParserRegistry.getParser(parserName).getLinkName().toString();
              }
          
          

          the ../warnings/api/xml REST api then gives me:

           
          <aggregatedWarningsProjectAction>
             <displayName>Compiler Warnings</displayName>
             <lastFinishedBuild>
                <number>344</number>
                <url>
          http://localhost:8080/job/code_coverage/job/Build_L1PHY_el1c_task_test_MAT_gcc/344/
                </url>
             </lastFinishedBuild>
             <warningsResultAction>
                <displayName>GNU C Compiler Warnings</displayName>
                <parser>GNU C Compiler 4 (gcc)</parser>
                <urlName>warnings18Result</urlName>
             </warningsResultAction>
             <warningsResultAction>
                <displayName>PC-Lint Warnings</displayName>
                <parser>PC-Lint</parser>
                <urlName>warnings0Result</urlName>
             </warningsResultAction>
          </aggregatedWarningsProjectAction>
          

          So i now get the urlName and parser name i can use.

          This is for a project, so to get the actual values for a particular build i can then do the calls to the particular parser urls.

          if i do ../warnings/api/xml?depth=2 then i get the full value tree (for the last build)

          <warningsResultAction>
          <name>warnings</name>
          <result>
          <newSuccessfulHighScore>false</newSuccessfulHighScore>
          <newZeroWarningsHighScore>false</newZeroWarningsHighScore>
          <numberOfFixedWarnings>0</numberOfFixedWarnings>
          <numberOfHighPriorityWarnings>0</numberOfHighPriorityWarnings>
          <numberOfLowPriorityWarnings>0</numberOfLowPriorityWarnings>
          <numberOfNewWarnings>0</numberOfNewWarnings>
          <numberOfNormalPriorityWarnings>2</numberOfNormalPriorityWarnings>
          <numberOfWarnings>2</numberOfWarnings>
          <pluginResult>SUCCESS</pluginResult>
          <referenceBuild>
          <number>343</number>
          <url>
          http://localhost:8080/job/code_coverage/job/Build_L1PHY_el1c_task_test_MAT_gcc/343/
          </url>
          </referenceBuild>
          <successfulHighScore>0</successfulHighScore>
          <successfulSinceBuild>0</successfulSinceBuild>
          <successfulSinceDate>0</successfulSinceDate>
          <warning/>
          <warning/>
          <warningsDelta>0</warningsDelta>
          <zeroWarningsHighScore>1200233384</zeroWarningsHighScore>
          <zeroWarningsSinceBuild>0</zeroWarningsSinceBuild>
          <zeroWarningsSinceDate>0</zeroWarningsSinceDate>
          </result>
          <successful>true</successful>
          <displayName>GNU C Compiler Warnings</displayName>
          <parser>GNU C Compiler 4 (gcc)</parser>
          <urlName>warnings18Result</urlName>
          </warningsResultAction>
          

          if i call .../buildNumber/warningsResult/api/xml
          then i get the collated values for a particular build.

          where do i need to add code to get the list of warnings actions in the /warningsResult/ call ?

          Morne Joubert added a comment - - edited I added the following in AggregatedWarningsProjectAction.java @Exported public List<WarningsResultAction> getWarningsResultAction() { List<WarningsResultAction> projectActions; // projectActions = this .getProject().getActions(WarningsResultAction.class); // can't use project, its actions list is allways empty // try getting the actions of the last build projectActions = this .getLastFinishedBuild().getActions(WarningsResultAction.class); return projectActions; } Inside WarningsResultAction.java i then added the exported and visibility fields @Exported(visibility = 2) @Override public String getUrlName() { return WarningsDescriptor.getResultUrl(parserName); } /** * Returns the parser group this result belongs to. * * @ return the parser group */ @Exported(visibility = 2) public String getParser() { return parserName; } @Exported(visibility = 2) @Override public String getDisplayName() { return ParserRegistry.getParser(parserName).getLinkName().toString(); } the ../warnings/api/xml REST api then gives me: <aggregatedWarningsProjectAction> <displayName> Compiler Warnings </displayName> <lastFinishedBuild> <number> 344 </number> <url> http://localhost:8080/job/code_coverage/job/Build_L1PHY_el1c_task_test_MAT_gcc/344/ </url> </lastFinishedBuild> <warningsResultAction> <displayName> GNU C Compiler Warnings </displayName> <parser> GNU C Compiler 4 (gcc) </parser> <urlName> warnings18Result </urlName> </warningsResultAction> <warningsResultAction> <displayName> PC-Lint Warnings </displayName> <parser> PC-Lint </parser> <urlName> warnings0Result </urlName> </warningsResultAction> </aggregatedWarningsProjectAction> So i now get the urlName and parser name i can use. This is for a project, so to get the actual values for a particular build i can then do the calls to the particular parser urls. if i do ../warnings/api/xml?depth=2 then i get the full value tree (for the last build) <warningsResultAction> <name> warnings </name> <result> <newSuccessfulHighScore> false </newSuccessfulHighScore> <newZeroWarningsHighScore> false </newZeroWarningsHighScore> <numberOfFixedWarnings> 0 </numberOfFixedWarnings> <numberOfHighPriorityWarnings> 0 </numberOfHighPriorityWarnings> <numberOfLowPriorityWarnings> 0 </numberOfLowPriorityWarnings> <numberOfNewWarnings> 0 </numberOfNewWarnings> <numberOfNormalPriorityWarnings> 2 </numberOfNormalPriorityWarnings> <numberOfWarnings> 2 </numberOfWarnings> <pluginResult> SUCCESS </pluginResult> <referenceBuild> <number> 343 </number> <url> http://localhost:8080/job/code_coverage/job/Build_L1PHY_el1c_task_test_MAT_gcc/343/ </url> </referenceBuild> <successfulHighScore> 0 </successfulHighScore> <successfulSinceBuild> 0 </successfulSinceBuild> <successfulSinceDate> 0 </successfulSinceDate> <warning/> <warning/> <warningsDelta> 0 </warningsDelta> <zeroWarningsHighScore> 1200233384 </zeroWarningsHighScore> <zeroWarningsSinceBuild> 0 </zeroWarningsSinceBuild> <zeroWarningsSinceDate> 0 </zeroWarningsSinceDate> </result> <successful> true </successful> <displayName> GNU C Compiler Warnings </displayName> <parser> GNU C Compiler 4 (gcc) </parser> <urlName> warnings18Result </urlName> </warningsResultAction> if i call .../buildNumber/warningsResult/api/xml then i get the collated values for a particular build. where do i need to add code to get the list of warnings actions in the /warningsResult/ call ?

          Ulli Hafner added a comment -

          The results are stored in AggregatedWarningsResultAction (one per parser per build). There you should add the code.

          Note that at the project level you should ask for actions of type AggregatedWarningsProjectAction (one per parser per project). There are no AggregatedWarningsResultActions registered for a job (project).

          Ulli Hafner added a comment - The results are stored in AggregatedWarningsResultAction (one per parser per build). There you should add the code. Note that at the project level you should ask for actions of type AggregatedWarningsProjectAction (one per parser per project). There are no AggregatedWarningsResultActions registered for a job (project).

            drulli Ulli Hafner
            mornejoubert Morne Joubert
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: