I 'm currently pushing to this accept server and, every time that I create a new release, I have to change the BRANCH that is accepted on line 4 of the code, how do I make it so that anything coming from release/ is accepted? I was thinking about something like BRANCH=release/* would that work?
#!/bin/bash
TARGET="<path_to_site>"
GIT_DIR="<path_to_repo>"
BRANCH="release/1.7"
while read oldrev newrev ref
do
# only checking out the master (or whatever branch you would like to deploy)
if [[ $ref = refs/heads/$BRANCH ]];
then
echo "Ref $ref received. Deploying ${BRANCH} branch to production..."
git --work-tree=$TARGET --git-dir=$GIT_DIR checkout -f
else
echo "Ref $ref received. Doing nothing: only the ${BRANCH} branch may be deployed on this server."
fi
done
You can use the ==
operator in Bash to do a regex comparison in the if
statement:
if [[ $ref == *"release/"* ]];
then
# ...
else
# ...
fi
This would match any reference that contains the string "release/"
, like for example "refs/heads/release/1.7"
.