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

Regex returns more matches than it should if errors are close together

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Minor
    • Resolution: Fixed
    • Component/s: token-macro-plugin
    • Labels:
      None
    • Environment:
      Jenkins version 2.89.4
      email-ext-plugin version 2.61
    • Similar Issues:

      Description

      Some of our tests return huge error files if the log file being parsed has matching errors that are closer together than the setting for "linesAfter". This is true even if "maxMatches" is set to just 1. Our setting in email-ext-plugin is:

       

      ${BUILD_LOG_REGEX, regex="(?m)^(nc\\w+:\\s+\\*E,|.\\bNG\\b|\\s*Error
      b|E-).
      $", linesBefore=5, linesAfter=10, maxMatches=5, showTruncatedLines=false
      }

       

      so this should limit the number of errors returned to 5. However, because the gap between matched errors is less than 10 lines this means that (in the Java code) the number of lines remaining to be written out gets reset to 10 on every subsequent match. The break condition for exiting the regex is the the number of lines remaining is 0 (amongst others) but this never happens for this case.

       

      This can be fixed by modifying BuildLogRegexContent.java on line 291. Change this line to:

      if (matched & (numMatches < maxMatches))

      and this will properly limit the number of matches to the value specified in numMatches and allow the regex to complete correctly.

        Attachments

          Activity

          Hide
          barnish Andrew Barnish added a comment -

          Alex Earl, did you find a solution for this issue yet?

          It is still causing very large emails to be sent from our Jenkins server.

          Show
          barnish Andrew Barnish added a comment - Alex Earl , did you find a solution for this issue yet? It is still causing very large emails to be sent from our Jenkins server.
          Hide
          slide_o_mix Alex Earl added a comment -

          I have not, been hammered at work and haven't had time to look into it more.

          Show
          slide_o_mix Alex Earl added a comment - I have not, been hammered at work and haven't had time to look into it more.
          Hide
          slide_o_mix Alex Earl added a comment -

          I am going to introduce a new parameter to this macro named "greedy" which will default to true (the current behavior). If greedy is set to false, then the macro will kick out of the check when numMatches >= maxMatches, which matches the behavior you are looking for. So, when I release the new version, you should add greedy=false to your macro usage.

          Show
          slide_o_mix Alex Earl added a comment - I am going to introduce a new parameter to this macro named "greedy" which will default to true (the current behavior). If greedy is set to false, then the macro will kick out of the check when numMatches >= maxMatches, which matches the behavior you are looking for. So, when I release the new version, you should add greedy=false to your macro usage.
          Hide
          scm_issue_link SCM/JIRA link daemon added a comment -

          Code changed in jenkins
          User: Alex Earl
          Path:
          src/main/java/org/jenkinsci/plugins/tokenmacro/impl/BuildLogRegexMacro.java
          src/test/java/org/jenkinsci/plugins/tokenmacro/impl/BuildLogRegexMacroTest.java
          src/test/resources/org/jenkinsci/plugins/tokenmacro/impl/JENKINS-49746-input.txt
          src/test/resources/org/jenkinsci/plugins/tokenmacro/impl/JENKINS-49746-output.txt
          http://jenkins-ci.org/commit/token-macro-plugin/135d69852894a4349446e7b78a244abe6b401102
          Log:
          Fix JENKINS-49746

          Added greedy parameter to break out of match checking when numMatches reaches maxMatches

          Show
          scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Alex Earl Path: src/main/java/org/jenkinsci/plugins/tokenmacro/impl/BuildLogRegexMacro.java src/test/java/org/jenkinsci/plugins/tokenmacro/impl/BuildLogRegexMacroTest.java src/test/resources/org/jenkinsci/plugins/tokenmacro/impl/ JENKINS-49746 -input.txt src/test/resources/org/jenkinsci/plugins/tokenmacro/impl/ JENKINS-49746 -output.txt http://jenkins-ci.org/commit/token-macro-plugin/135d69852894a4349446e7b78a244abe6b401102 Log: Fix JENKINS-49746 Added greedy parameter to break out of match checking when numMatches reaches maxMatches
          Hide
          slide_o_mix Alex Earl added a comment -

          token-macro 2.5 has been released with this fix

          Show
          slide_o_mix Alex Earl added a comment - token-macro 2.5 has been released with this fix

            People

            Assignee:
            slide_o_mix Alex Earl
            Reporter:
            rwilkinson Richard Wilkinson
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: