Back to Home

The power of CI/CD Deployment Hooks

Published on

Tech Devops Best Practices

The beauty of Continuous Integration (CI) and Continuous Delivery (CD) is that developers on a project are able to deliver frequently.

However, quick delivery does not always mean successful delivery, and this is where Deployment hooks comes in. We want confidence that latest changes do not break existing project builds.

Lets say you work on a web development project alongside many other developers, you want to deliver features quickly! But also, you need to make sure that these new features actually work. Sometimes, it may work on your machine, but not on the same metal that your site is hosted on.

How your site is hosted, is not always the same environment or the same config as your development device, for example you may have dozens of hosted builds with all different config setup. As a developer, whilst you could make sure you have verified your changes on all those possible config builds, this takes time away from actual development. Again, You want to deliver features quickly.

The deploy hook

There are various git related hooks that improve the quality of committed and pushed code. However, the deploy hook is the next sensible pathway to improved quality. These are HTTP post requests that trigger deployments and goes through your app's build stages.

Typically, on a project, CI/CD is setup for new changes to the tracked branch (main) on a repository, however, these deploy hooks can be triggered from other actions.

Most usefully, the Pull request creation / update. This allows new features to be built on your ci/cd platform, if the project fails to build, you are quickly alerted, and your repository platform can be set up to even block any merges to the branch until a successful build takes place.

Vercel failure

And then after a couple of changes...

A successful build!

Vercel success

Key things to factor in

Remember, a 'Best Practice' is only useful, is if it is used. On a project where new features are rapidly getting made, ideally you want to keep this momentum up. If the build checks are taking an hour or longer for each Pull Request update, then this will severly impact productivity.

As similar to tests, you want it to fail fast, then developers working on the feature are able to quickly address the fixes whilst the work is still in their cognitive load.

You may need to create an somewhat minimalised version of your build process to achieve quicker builds, and then a full build verification at a final check, this could be triggered after an X amount of approvals on the pull request.

Creating a custom deployment hook benefits you the flexixibity of what you can achieve, although many decent deployment platforms have incredible integrations with popular repositories such as Github.


The example I have shown is my Netlify & Vercel deployment hooks with my Github repository for my blog project.