How to Use a post-receive Git hook to mark a deployment in NewRelic


I recently started monitoring my systems with NewRelic. Fantastic tool.

One fun feature they provide is that you can mark in NewRelic’s dashboard when you’ve deployed new code. This way you can compare your site performance before and after the deploy.

curl -H "x-api-key:YOUR_API_KEY_HERE" -d "deployment[app_name]=iMyFace.ly Production" -d "deployment[description]=This deployment was sent using curl" -d "deployment[changelog]=many hands make light work" -d "deployment[user]=Joe User" https://api.newrelic.com/deployments.xml

Using Git’s post-receive hook is perfect for this, especially since I already use it to deploy my sites to the various servers.

The only question I had was, how would I get the various variables from the post-receive hook into the curl statement?

Well, here you go:

description=$(git log -1 --pretty=format:%s)
author=$(git log -1 --pretty=format:%cn)
revision=$(git log -1 --pretty=format:%T)

Now you can do this:

curl -H "x-api-key:YOUR_API_KEY_HERE" -d "deployment[app_name]=iMyFace.ly Production" -d "deployment[description]=$description" -d "deployment[user]=$author" -d"deployment[revision]=$revision" https://api.newrelic.com/deployments.xml