I would like to add multiple post-receive hook scripts to a git repository on my own server. For example: triggering CI, and posting to slack.
How can I add more than one script?
You can only have one post-receive script, so you'll have to use that one to call multiple scripts.
On the server in the
/PATH/TO/GIT.git/hooks/post-receive file, put the following:
#!/bin/bash while read oldrev newrev refname; do for hook in $GIT_DIR/hooks/post-receive.d/*; do echo -e "\e[44m\e[97m Running hook: $hook \e[0m" echo $oldrev $newrev $refname | $hook done done exit 0
Then put all your post-receive scripts inside a new
post-receive.d/ directory. Make sure the script files are executable.
/PATH/TO/GIT.git/hooks/ └── post-receive.d └── SCRIPT1 └── SCRIPT2