Last active
December 26, 2017 10:06
-
-
Save Aleksandr-ru/53be84be619e08f63c488b1568a5553a to your computer and use it in GitHub Desktop.
Git bare repo post-receive hook for automatic deploy
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
#!/bin/sh | |
while read oldrev newrev refname | |
do | |
#echo post-receive: $oldrev $newrev $refname >> ~/post-receive.log | |
if [ "$oldrev" != "$newrev" ]; then | |
branch=$(git rev-parse --symbolic --abbrev-ref $refname) | |
if [ "master" == "$branch" ]; then | |
echo Deploying $branch branch to production | |
ssh -i ~/.ssh/gitbot.id_rsa gitbot@production-host.example.com "~/pull-repo-script.sh" | |
# don't forget to add id_rsa.pub to /home/gitbot/.ssh/authorized_keys at production-host.example.com | |
elif [ "develop" == "$branch" ]; then | |
echo Deploying $branch branch to webarm-dev | |
ssh -i ~/.ssh/gitbot.id_rsa gitbot@development-host.example.com "~/pull-repo-script.sh" | |
# don't forget to add id_rsa.pub to /home/gitbot/.ssh/authorized_keys at development-host.example.com | |
else | |
echo "Branch $branch is not deployable" | |
fi | |
fi; | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment