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

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

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • token-macro-plugin
    • None
    • Jenkins version 2.89.4
      email-ext-plugin version 2.61

      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.

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

              Created:
              Updated:
              Resolved: