Last active
May 31, 2024 01:41
-
-
Save pingkunga/2a6b58f77b9da938ec644aa7fcf04536 to your computer and use it in GitHub Desktop.
Check Branch Name match with pattern
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Regex to match branch name such as | |
origin/master >> match exactly | |
origin/master1 >> Not match | |
origin/develop >> match exactly | |
origin/develop1 >> Not match | |
origin/release8.8.17 >> match | |
origin/release8.8.18 >> match | |
origin/release10.99.180 >> match | |
origin/release8.8.17.0 >> not match | |
origin/release8.8.17/feature_aaa >> not match | |
origin/release8.8.17/fix >> not match | |
origin/release/8.8.18 matches the regex | |
origin/release/8.8.18.956 not match the regex | |
origin/hotfix/8.8.18.4_AnyString matches the regex | |
origin/hotfix/8.8.18.5_Asec matches the regex | |
origin/hotfix/8.8.18.4AnyString not match the regex | |
origin/hotfix/8.8.18.5_SAN matches the regex | |
origin/uat/8.8.18.4_AnyString matches the regex | |
origin/uat/8.8.18.5_mktsec matches the regex | |
origin/uat/8.8.18.4AnyString not match the regex | |
origin/uat/8.8.18.5_sab matches the regex | |
*/ | |
println("Hello world") | |
println("==============================") | |
def branchNames = ['origin/master', 'origin/master1', 'origin/develop', 'origin/develop1', 'origin/release8.8.17', 'origin/release8.8.18', 'origin/release10.99.180', 'origin/release8.8.17.0', 'origin/release8.8.17/feature_aaa', 'origin/release8.8.17/fix', 'origin/release/8.8.18','origin/release/8.8.18.956','origin/hotfix/8.8.18.4_AnyString', 'origin/hotfix/8.8.18.5_Asec', 'origin/hotfix/8.8.18.4AnyString', 'origin/hotfix/8.8.18.5_SAN','origin/uat/8.8.18.4_AnyString', 'origin/uat/8.8.18.5_mktsec', 'origin/uat/8.8.18.4AnyString', 'origin/uat/8.8.18.5_sab'] | |
def regex = /^origin\/(master|develop|release\d+\.\d+\.\d+|release\/\d+\.\d+\.\d+|hotfix\/\d+\.\d+\.\d+\.\d+_.*|uat\/\d+\.\d+\.\d+\.\d+_.*)$/ | |
for (branchName in branchNames) { | |
if ((branchName =~ regex).matches()) { | |
println "${branchName} matches the regex \n" | |
} else { | |
println "${branchName} not match the regex \n" | |
} | |
} | |
/* | |
Sample run: http://tpcg.io/_0RBV1S | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment