| 1 | #!/bin/bash |
| 2 | # Directory where to deploy files from repository |
| 3 | DPTARGET="" |
| 4 | # Directory containing repository |
| 5 | DPGIT_DIR="{{GITDIR}}/{{PROJECT}}.git" |
| 6 | # Branch that is going to be deployed to server |
| 7 | DPBRANCH="master" |
| 8 | |
| 9 | while read oldrev newrev ref |
| 10 | do |
| 11 | # if DPTARGET is empty we don't want deploy for this project |
| 12 | if [[ ! "" == $DPTARGET ]]; then |
| 13 | # let's check that we are deploying to the correct branch |
| 14 | if [[ $ref = refs/heads/${DPBRANCH} ]]; then |
| 15 | echo "Ref $ref received. Deploying ${DPBRANCH} branch to production..." |
| 16 | git --work-tree=$DPTARGET --git-dir=$DPGIT_DIR checkout -f $DPBRANCH |
| 17 | NOW=$(date +"%d%m%Y-%H%M") |
| 18 | git tag release_$NOW $DPBRANCH |
| 19 | echo " /===============================" |
| 20 | echo " | DEPLOYMENT COMPLETED" |
| 21 | echo " | Target branch: $DPTARGET" |
| 22 | echo " | Target folder: $DPGIT_DIR" |
| 23 | echo " | Tag name : release_$NOW" |
| 24 | echo " \==============================" |
| 25 | else |
| 26 | echo "Ref $ref received. Doing nothing: only the ${DPBRANCH} branch may be deployed on this server." |
| 27 | fi |
| 28 | else |
| 29 | echo "Target directory not declared. Skipping deploy to server." |
| 30 | fi |
| 31 | done |