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 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).

          Morne Joubert added a comment -

          ok, i have found a solution that gives me what i want with very minor changes
          In WarningsResultAction i have just added 2 @Exported lines.

          public WarningsResultAction(final AbstractBuild<?, ?> owner, final HealthDescriptor healthDescriptor, final WarningsResult result, final String parserName)

          { super(owner, new WarningsHealthDescriptor(healthDescriptor, ParserRegistry.getParser(parserName).getParserName()), result); this.parserName = parserName; }

          @Exported
          @Override
          public String getUrlName()

          { return WarningsDescriptor.getResultUrl(parserName); }

          /**

          • Returns the parser group this result belongs to.
            *
          • @return the parser group
            */
            @Exported
            public String getParser() { return parserName; }

          how do i get this back into the code ?

          Morne Joubert added a comment - ok, i have found a solution that gives me what i want with very minor changes In WarningsResultAction i have just added 2 @Exported lines. public WarningsResultAction(final AbstractBuild<?, ?> owner, final HealthDescriptor healthDescriptor, final WarningsResult result, final String parserName) { super(owner, new WarningsHealthDescriptor(healthDescriptor, ParserRegistry.getParser(parserName).getParserName()), result); this.parserName = parserName; } @Exported @Override public String getUrlName() { return WarningsDescriptor.getResultUrl(parserName); } /** Returns the parser group this result belongs to. * @return the parser group */ @Exported public String getParser() { return parserName; } how do i get this back into the code ?

          Ulli Hafner added a comment -

          The easiest way would be a pull request.

          Ulli Hafner added a comment - The easiest way would be a pull request .

          Morne Joubert added a comment -

          thanks,

          I think i got it correct (i am a P4,svn guy...) but the builds are failing due to a dependency.
          https://jenkins.ci.cloudbees.com/job/plugins/job/warnings-plugin/289/org.jvnet.hudson.plugins$warnings/console

          Morne Joubert added a comment - thanks, I think i got it correct (i am a P4,svn guy...) but the builds are failing due to a dependency. https://jenkins.ci.cloudbees.com/job/plugins/job/warnings-plugin/289/org.jvnet.hudson.plugins$warnings/console

          Morne Joubert added a comment -

          hi, i just wanted to check if my change have actually made it into a release version ?

          Morne Joubert added a comment - hi, i just wanted to check if my change have actually made it into a release version ?

          Ulli Hafner added a comment - https://github.com/jenkinsci/warnings-plugin/commit/b39e09aeda5682c5e56b17d048cf2db6115050a9 Should be in 4.49, see https://github.com/jenkinsci/warnings-plugin/commits/master

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

              Created:
              Updated:
              Resolved: