Skip to content

Commit 206724b

Browse files
enforce branch naming for pipelines
1 parent ad9dcdb commit 206724b

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

cicd/2-cicd/deploy-cicd.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,19 @@ fi
1616

1717
# Default to main branch, but support pipelines using other branches
1818
TARGET_BRANCH=${TARGET_BRANCH-'main'}
19+
1920
if [ "$TARGET_BRANCH" == "main" ]
2021
then
2122
STACK_NAME="javabuilder-cicd"
2223
else
23-
STACK_NAME="javabuilder-${TARGET_BRANCH}-cicd"
24+
# only allow alphanumeric branch names that may contain an internal hyphen.
25+
# to avoid complicated logic elsewhere, we're constraining it here.
26+
if [[ "$TARGET_BRANCH" =~ ^[a-z0-9]([-a-z0-9]*[a-z0-9])$ ]]; then
27+
STACK_NAME="javabuilder-${TARGET_BRANCH}-cicd"
28+
else
29+
echo "Invalid branch name '${TARGET_BRANCH}', branches must be alphanumeric and may contain hyphens."
30+
exit
31+
fi
2432
fi
2533

2634
ENVIRONMENT_TYPE=${ENVIRONMENT_TYPE-'standard'}

0 commit comments

Comments
 (0)