Quick & Dirty Way Of Notifying Everyone When Code Deploys

Slack Notifications Using A Git Pull Hook

Cory Kennedy-Darby
2 min readAug 16, 2015

Before you dive into this written piece, I want to emphasize that there are better practices to managing deployments than what is outlined in this.

This solution works on the premise of git cloning the repository onto the server itself.

Do not accidentally expose the .git folder to the server’s web server; Doing this would expose the source code to the outside world.

Snippet

For this to work you are required to create a file named ‘post-merge’ located in the git hooks folder of your git repository on the server.

On a Linux distribution, it would look similar to this:

#Assuming git clone is at /home/ckdarby/startup/
$ vim /home/ckdarby/startup/.git/hooks/post-merge

Contents Of post-merge

#Assuming git clone is at /home/ckdarby/startup/
$ chmod +x /home/ckdarby/startup/.git/hooks/post-merge

Configuration

The first thing that is required for this to work is to generate an incoming web hook on Slack. To add a web hook to your Slack organization, visit ‘Incoming WebHooks’.

Following the instructions, Slack will provide a web hook URL.

#Run this on the server in the git repository
#Replace WEBHOOK_URL with the webhook url slack provided
$ git config hooks.slack.webhook-url 'WEBHOOK_URL'

Deploy it! Slack, Tell Everyone!

With the git hook in place, every time someone runs the command:

git pull

Slack will notify the configured channel with a brief summary of the latest commit hash running on that server. It’ll look something like this…

Co-founders @ GamerBet committing & deploying.

Wrap Up

There are many tools created for streamlining the deployment process, but there are still companies & developers that are not using those tools.

Sometimes it makes sense to pass on the tools. Other times it might be laziness, red tape, time or other factors.

No matter what the reason, having anything in place that provides communication is better than absolute silence. That is why this was hacked together to provide the quick & dirty solution.

If you enjoyed this article, please recommend and or share it.

--

--