For our latest projects we have been using Fabric to automate the deployment workflow of our applications. Since all developers are connected to HipChat (which is already integrated with the rest of our Atlassian stack) we thought it would be useful to write a notification in the project chat room in HipChat each time an application is being deployed.

Configuring this was surprisingly simple. You just need to pick the right tools.

Basically sending messages to a HipChat room is nothing more than a Curl call. But we made our life easy by just installing a small Python library (wink)

On Debian you can just run (we assume you already have a working Fabric installation and script):

sudo pip install python-simple-hipchat

Our Python function that wraps the library:

def notify_hipchat(message, color):
    try:
        import hipchat
    except ImportError:
        pass
    else:
        hc = hipchat.HipChat(token="YOUR-TOKEN-GOES-HERE")
        hc.method("rooms/message", "POST", {
            "room_id": "YOUR-ROOMID-GOES-HERE",
            "from": "Deploy-o-matic",
            "message": message,
            "message_format": "html",
            "color": color
        })

We have wrapped the "import hipchat" statement in a try-catch statement because this way the deployment won't completely fail just because someone didn't install the library on his machine.

Notifying the chatroom a deploy has started:

notify_hipchat("Deploying branch %s to %s..." % (env.branch, env.name), "yellow")

Notifying a deploy was completed successfully:

notify_hipchat("Successfully deployed branch %s to %s!" % (env.branch, env.name), "green")

Notifying something went horribly wrong:

notify_hipchat("Deploy failed!", "red")

Here's an example of what we were able to achieve:

Hip chat notifications fabric