I have code with expression where i am trying to enforce the branching Naming convention
valid_branch_regex="^(feature|bugfix|release|hotfix)([-\d-]+)([a-z]+$)"
Valid Case : Feature-1231-SomeName
Invalid Case : Feature-SomeName-1223 | SomeName-232-Feature
but not able to execute this with bash script , Every time its failing with Invalid Case even for the correct inputs .
Bash Version : 3.182.0
#!/usr/bin/env bash
LC_ALL=C
#local_branch="$(Build.SourceBranchName)"
shopt -s nocasematch
local_branch="Feature-92784-PlotBreakingFix"
valid_branch_regex="^(feature|bugfix|release|hotfix)([-\d-]+)([a-z]+$)"
message="There is something wrong with your branch name. Branch names in this project must adhere to this contract: $valid_branch_regex. Your commit will be rejected. You should rename your branch to a valid name and try again."
if [[ $local_branch =~ $valid_branch_regex ]];
then
echo "Branch Name: $local_branch"
echo "Status:Valid"
shopt -u nocasematch
exit 0
else
echo "Branch Name: $local_branch"
echo "Error: $message"
shopt -u nocasematch
exit 1
fi