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

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

XMLWordPrintable

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

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

              Created:
              Updated:
              Resolved: