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

Comment log checker does not handle build names with regex special characters

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      The regular expressions created for looking for build started and build finished message in the comments is inserting the build job name directly as part of the regular expression. That works if the build job name is a simple name, but in our case we had some text in parentheses in the name of the build job. The regex parser took that as a capture group so the match failed because it would not match the parentheses in the name.

      You should use a capture group for the job name and then compare the captured text to the build job name or else use java.util.regex.Pattern.quote to add any necessary escape characters. Here is a patch that fixes it:

      diff --git a/src/main/java/stashpullrequestbuilder/stashpullrequestbuilder/StashRepository.java b/src/main/java/stashpullrequestbuilder/stashpullrequestbuilder/StashRepository.java
      index 2d9bf76..efca26d 100644
      --- a/src/main/java/stashpullrequestbuilder/stashpullrequestbuilder/StashRepository.java
      +++ b/src/main/java/stashpullrequestbuilder/stashpullrequestbuilder/StashRepository.java
      @@ -157,8 +157,9 @@ public class StashRepository {
                           }
      
                           //These will match any start or finish message -- need to check commits
      -                    String project_build_start = String.format(BUILD_START_REGEX, builder.getProject().getDisplayName());
      -                    String project_build_finished = String.format(BUILD_FINISH_REGEX, builder.getProject().getDisplayName());
      +                    String escapedBuildName = Pattern.quote(builder.getProject().getDisplayName());
      +                    String project_build_start = String.format(BUILD_START_REGEX, escapedBuildName);
      +                    String project_build_finished = String.format(BUILD_FINISH_REGEX, escapedBuildName);
                           Matcher startMatcher = Pattern.compile(project_build_start, Pattern.CASE_INSENSITIVE).matcher(content);
                           Matcher finishMatcher = Pattern.compile(project_build_finished, Pattern.CASE_INSENSITIVE).matcher(content);
      
      
      

        Attachments

          Activity

          Hide
          nightwolfzor Night Wolf added a comment -

          Could you raise an issue and a PR fix for this one on github? https://github.com/nemccarthy/stash-pullrequest-builder-plugin

          Show
          nightwolfzor Night Wolf added a comment - Could you raise an issue and a PR fix for this one on github? https://github.com/nemccarthy/stash-pullrequest-builder-plugin
          Hide
          dalewking Dale King added a comment -

          I reopened the issue I originally created on Github. Cannot give you a PR as that would require me to violate my boycott of Github. I gave you a patch and the change is trivial.

          Show
          dalewking Dale King added a comment - I reopened the issue I originally created on Github. Cannot give you a PR as that would require me to violate my boycott of Github. I gave you a patch and the change is trivial.
          Hide
          mzielinski Maciej Zielinski added a comment - - edited

          I created PR (it is based on changes made in nemccarthy/stash-pullrequest-builder-plugin repository):
          https://github.com/jenkinsci/stash-pullrequest-builder-plugin/pull/17

          Can you merge it, and create new version of plugin? This bug is pretty crucial for us. Most of our jobs have chars like [ or ] in display name, and because of that we cannot use this plugin (it is triggering all the time).

          Show
          mzielinski Maciej Zielinski added a comment - - edited I created PR (it is based on changes made in nemccarthy/stash-pullrequest-builder-plugin repository): https://github.com/jenkinsci/stash-pullrequest-builder-plugin/pull/17 Can you merge it, and create new version of plugin? This bug is pretty crucial for us. Most of our jobs have chars like [ or ] in display name, and because of that we cannot use this plugin (it is triggering all the time).
          Hide
          mzielinski Maciej Zielinski added a comment -

          Hello, do you have any update in this topic?

          Show
          mzielinski Maciej Zielinski added a comment - Hello, do you have any update in this topic?
          Hide
          nickbrown Nicholas Brown added a comment -
          Show
          nickbrown Nicholas Brown added a comment - https://github.com/jenkinsci/stash-pullrequest-builder-plugin/pull/17 has been merged and a release made.

            People

            Assignee:
            nemccarthy nathan m
            Reporter:
            dalewking Dale King
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: