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

Regex match fails - "Mentioned somewhere in commit message"

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Critical Critical
    • jira-ext-plugin
    • None

      Regex matching fails to match pattern found in log message.

      Jenkins version 2.7.1
      Jira-ext plugin version 0.5

      Jira-ext plugin settings:

      jira-ext Config
      JIRA Base URL VALID_URL (tested with find custom fields)
      JIRA Username VALID_USER (see above)
      JIRA Password VALID_PASSWD (see above)
      Ticket Pattern EXITEVOISSUES-,EXITEVODEV-
      Verbose Logging (Enabled)
      Timeout 10

      svn log message (verbose)
      ------------------------------------------------------------------------
      r16769 | nb79311 | 2016-07-21 12:09:54 +0200 (Thu, 21 Jul 2016) | 2 lines
      Changed paths:
      M /trunk/src/CMakeLists.txt

      Jira key: EXITEVODEV-1309
      Comments: Test automatic Jira update
      ------------------------------------------------------------------------

      Output:

      Updating JIRA tickets
      ChangeLogSet class: class hudson.scm.SubversionChangeLogSet
      ERROR Updating jira notifications
      java.lang.IllegalStateException: No match found
      at java.util.regex.Matcher.group(Matcher.java:536)
      at org.jenkinsci.plugins.jiraext.view.MentionedInCommitStrategy.getJiraIssuesFromChangeSet(MentionedInCommitStrategy.java:111)
      at org.jenkinsci.plugins.jiraext.view.AbstractParsingIssueStrategy.getJiraCommits(AbstractParsingIssueStrategy.java:60)
      at org.jenkinsci.plugins.jiraext.view.JiraExtBuildStep.perform(JiraExtBuildStep.java:59)
      at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
      at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:779)
      at hudson.model.Build$BuildExecution.build(Build.java:205)
      at hudson.model.Build$BuildExecution.doRun(Build.java:162)
      at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:534)
      at hudson.model.Run.execute(Run.java:1741)
      at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
      at hudson.model.ResourceController.execute(ResourceController.java:98)
      at hudson.model.Executor.run(Executor.java:410)
      Operation: Update a Field
      Finish updating JIRA tickets

          [JENKINS-36844] Regex match fails - "Mentioned somewhere in commit message"

          Smouch Smouch added a comment - - edited

          I have finally managed to get some additional log information out of this plugin

          I added a few lines of logging within MentionedInCommitStrategy.java as follows:

          this._logger.log(Level.FINE,"Message text BEGIN:");
          this._logger.log(Level.FINE,msg);
          this._logger.log(Level.FINE,":Message text END");
          this._logger.log(Level.FINE,"JiraPrefix BEGIN:");
          this._logger.log(Level.FINE,validJiraPrefix);
          this._logger.log(Level.FINE,":JiraPrefix END");

          Trying to understand why the string search would fail

          Here is the resulting log message for a single test issue:

          Jul 26, 2016 10:53:00 AM FINE org.jenkinsci.plugins.jiraext.view.MentionedInCommitStrategy

          Message text BEGIN:

          Jul 26, 2016 10:53:00 AM FINE org.jenkinsci.plugins.jiraext.view.MentionedInCommitStrategy

          Jira key: EXITEVODEV-1309
          Comments: Test Jira updater

          Jul 26, 2016 10:53:00 AM FINE org.jenkinsci.plugins.jiraext.view.MentionedInCommitStrategy

          :Message text END

          Jul 26, 2016 10:53:00 AM FINE org.jenkinsci.plugins.jiraext.view.MentionedInCommitStrategy

          JiraPrefix BEGIN:

          Jul 26, 2016 10:53:00 AM FINE org.jenkinsci.plugins.jiraext.view.MentionedInCommitStrategy

          EXITEVODEV

          Jul 26, 2016 10:53:00 AM FINE org.jenkinsci.plugins.jiraext.view.MentionedInCommitStrategy

          :JiraPrefix END

          So, there seems to be some kind of fundamental issue with the way the string search is being used. Clearly the message text contains the regex being searched for, yet the search is failing.

          Smouch Smouch added a comment - - edited I have finally managed to get some additional log information out of this plugin I added a few lines of logging within MentionedInCommitStrategy.java as follows: this._logger.log(Level.FINE,"Message text BEGIN:"); this._logger.log(Level.FINE,msg); this._logger.log(Level.FINE,":Message text END"); this._logger.log(Level.FINE,"JiraPrefix BEGIN:"); this._logger.log(Level.FINE,validJiraPrefix); this._logger.log(Level.FINE,":JiraPrefix END"); Trying to understand why the string search would fail Here is the resulting log message for a single test issue: Jul 26, 2016 10:53:00 AM FINE org.jenkinsci.plugins.jiraext.view.MentionedInCommitStrategy Message text BEGIN: Jul 26, 2016 10:53:00 AM FINE org.jenkinsci.plugins.jiraext.view.MentionedInCommitStrategy Jira key: EXITEVODEV-1309 Comments: Test Jira updater Jul 26, 2016 10:53:00 AM FINE org.jenkinsci.plugins.jiraext.view.MentionedInCommitStrategy :Message text END Jul 26, 2016 10:53:00 AM FINE org.jenkinsci.plugins.jiraext.view.MentionedInCommitStrategy JiraPrefix BEGIN: Jul 26, 2016 10:53:00 AM FINE org.jenkinsci.plugins.jiraext.view.MentionedInCommitStrategy EXITEVODEV Jul 26, 2016 10:53:00 AM FINE org.jenkinsci.plugins.jiraext.view.MentionedInCommitStrategy :JiraPrefix END So, there seems to be some kind of fundamental issue with the way the string search is being used. Clearly the message text contains the regex being searched for, yet the search is failing.

          Jack Pei added a comment - - edited

          I ran into the same issue and determined the exact cause.

           

          In my case the problem is that the commit message is a multi-line message and JIRA # appears on a line that is not the last line. Ticket Pattern is configured to be "BLU-", and the commit message itself is:

           

          BLU-1160 New Viewer - Exam List - Filter changes

          – commit details removed –

          Issue:BLU-1160

           

          The problem is in MentionedInCommitStrategy.java, line 106-111:

          final String regex = "^([0-9]*).*$";
          final Pattern pattern = Pattern.compile(regex);
          final Matcher matcher = pattern.matcher(firstOccurrence);
          matcher.matches();
          final String ticketNumber = matcher.group(1);
          

          It finds the first occurrence of "BLU-1160", but when it tries to match regex pattern, the match fails because in regular expression, most implementations including Java don't match newline against ".", thus nothing matches.

           

          The fix should be simple, as in this case the only thing needs to be matched is the number string at the beginning of the string, line 106 can be changed to:

          final String regex = "^([0-9]*)";

           

          Also, I'd suggest check groupCount() before calling group(1), since in rare occasions there may not be a match. This could happen when developer made a typo when checking in, or in our case, when dev talks about something else, for example, a message like "Fixed the issue with BLU-RAY disc reading" which would match against JIRA prefix "BLU-" but the regex matching will fail and it would throw exception like:

          java.lang.IllegalStateException: No match found15:57:36 at java.util.regex.Matcher.group(Unknown Source)15:57:36 at org.jenkinsci.plugins.jiraext.view.MentionedInCommitStrategy.getJiraIssuesFromChangeSet(MentionedInCommitStrategy.java:111)

           

          Jack Pei added a comment - - edited I ran into the same issue and determined the exact cause.   In my case the problem is that the commit message is a multi-line message and JIRA # appears on a line that is not the last line. Ticket Pattern is configured to be "BLU-", and the commit message itself is:   BLU-1160 New Viewer - Exam List - Filter changes – commit details removed – Issue:BLU-1160   The problem is in MentionedInCommitStrategy.java, line 106-111: final String regex = "^([0-9]*).*$" ; final Pattern pattern = Pattern.compile(regex); final Matcher matcher = pattern.matcher(firstOccurrence); matcher.matches(); final String ticketNumber = matcher.group(1); It finds the first occurrence of "BLU-1160", but when it tries to match regex pattern, the match fails because in regular expression, most implementations including Java don't match newline against ".", thus nothing matches.   The fix should be simple, as in this case the only thing needs to be matched is the number string at the beginning of the string, line 106 can be changed to: final String regex = "^([0-9]*)" ;   Also, I'd suggest check groupCount() before calling group(1), since in rare occasions there may not be a match. This could happen when developer made a typo when checking in, or in our case, when dev talks about something else, for example, a message like "Fixed the issue with BLU-RAY disc reading" which would match against JIRA prefix "BLU-" but the regex matching will fail and it would throw exception like: java.lang.IllegalStateException: No match found15:57:36 at java.util.regex.Matcher.group(Unknown Source)15:57:36 at org.jenkinsci.plugins.jiraext.view.MentionedInCommitStrategy.getJiraIssuesFromChangeSet(MentionedInCommitStrategy.java:111)  

            dalvizu Dan Alvizu
            smouch Smouch Smouch
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: