Skip to content

Commit

Permalink
added a warning message when the number in wildcard is out of range o…
Browse files Browse the repository at this point in the history
…f the job name
  • Loading branch information
patrikcerbak committed Oct 19, 2023
1 parent 2c4ae9d commit e4ec709
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private String parseToRegex(String spliterator, String query) {
String converted = query;

// finds %N in the query from Jenkins config and replaces it with corresponding part of job name
Pattern p = Pattern.compile("%\\{((N\\+|N-)?[0-9]+|S|SPLIT)\\}");
Pattern p = Pattern.compile("%\\{((N-)?[0-9]+|S|SPLIT)\\}");
Matcher m = p.matcher(converted);

while (m.find()) {
Expand All @@ -92,10 +92,15 @@ private String parseToRegex(String spliterator, String query) {
number = Integer.parseInt(insideBrackets) - 1;
}

if (number < 0 || number >= splitJob.length) {
System.err.println("WARNING: The number given in the --regex argument of \"Comparator links\" section is out of range of the job name!");
return "The number given is out of range of the job name!";
}

replacement = splitJob[number];
}

converted = converted.replaceFirst("%\\{((N\\+|N-)?[0-9]+|S|SPLIT)\\}", replacement);
converted = converted.replaceFirst("%\\{((N-)?[0-9]+|S|SPLIT)\\}", replacement);
m = p.matcher(converted);
}

Expand Down

0 comments on commit e4ec709

Please sign in to comment.