Skip to content

Commit ea1ea43

Browse files
Improve RegexBasedFilter doc (#1463)
* Improve RegexBasedFilter doc Added example and some explanation related to regular expressions used in RegexBasedFilter. * Apply suggestions from code review Co-authored-by: Kris Stern <[email protected]> * fixing formatting Co-authored-by: Kris Stern <[email protected]> * Apply suggestions from code review Co-authored-by: Kris Stern <[email protected]> * Apply suggestions from code review Co-authored-by: Kris Stern <[email protected]> --------- Co-authored-by: Kris Stern <[email protected]>
1 parent 95f7022 commit ea1ea43

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

README.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,31 @@ This plugin can be used with Matrix/Multi-configuration jobs together with the [
482482

483483
## Advanced features
484484
### Branch filtering
485-
Triggers may be filtered based on the branch name, i.e. the build will only be allowed for selected branches. On the project configuration page, when you configure the GitLab trigger, you can choose 'Filter branches by name' or 'Filter branches by regex.' Filter by name takes comma-separated lists of branch names to include and/or exclude from triggering a build. Filter by regex takes a Java regular expression to include and/or exclude.
485+
Triggers may be filtered based on the branch name, i.e. the build will only be allowed for selected branches. On the project configuration page, when you configure the GitLab trigger, you can choose 'Filter branches by name' or 'Filter branches by regex.' Filter by name takes comma-separated lists of branch names to include and/or exclude from triggering a build. Filter by regex takes a Java regular expression to include and/or exclude. For example, to exclude all branches containing the word "feature", you can use the following regular expression: `^(?:(?!feature).)*$`.
486+
On a similar note, the regular expression `^(?!.*master).*$` will mean - all branches not matching master. This is a regular expression that uses negative lookahead to match any string that does not contain the word "master". Here's a breakdown of how it works:
487+
488+
^: Anchors the match to the beginning of the string.
489+
(: Starts a group that will be used for the negative lookahead.
490+
?!: Indicates a negative lookahead assertion - finds all that does not match.
491+
.*: Matches any number of characters (except for a newline) zero or more times.
492+
master: should not match master.
493+
): Ends the group.
494+
$: Anchors the match to the end of the string.
495+
496+
Keep in mind that the `RegexBasedFilter` feature is case-sensitive by default. If you want to make it case-insensitive, you can use the `(?i)` flag at the beginning of your regular expression pattern. For example: `^(?i)(?:(?!feature).)*$`.
497+
498+
Here is an example pipeline script that shows how to use the `RegexBasedFilter` feature in the GitLab trigger:
499+
500+
```
501+
triggers {
502+
gitlab(
503+
triggerOnPush: true,
504+
triggerOnMergeRequest: false,
505+
branchFilterType: "RegexBasedFilter",
506+
targetBranchRegex: '^(?:(?!feature).)*$'
507+
)
508+
}
509+
```
486510

487511
**Note:** This functionality requires access to GitLab and a git repository url already saved in the project configuration. In other words, when creating a new project, the configuration needs to be saved *once* before being able to add branch filters. For Pipeline jobs, the configuration must be saved *and* the job must be run once before the list is populated.
488512

0 commit comments

Comments
 (0)