Using build hook payload to trigger a different build command on Netlify

All started by the following tweet:

Reading the Twitter conversation, I wondered if it was possible to pass data to the build hook.

Heading to Netlify documentation I found exactly what I need: https://docs.netlify.com/configure-builds/build-hooks/#payload

Great! Now the deploy script will look something like:

#!/bin/sh

if [ "$INCOMING_HOOK_BODY" = "full" ]; then
echo "Full build"
gatsby clean && gatsby build
else
echo "Simple build"
gatsby build
fi;

This means:

curl -X POST -d {} https://api.netlify.com/build_hooks/YOUR_TOKEN

Will execute

gatsby build

And

curl -X POST -d 'full' https://api.netlify.com/build_hooks/YOUR_TOKEN

Will execute

gatsby clean && gatsby build

Code example

You can find, bellow, a full example using Github Actions to schedule the build.

Don’t forget to set up the build script on Netlify!

Oh! One last thing!

The best part, for me, is the reply from Jason Lengstorf 😋 😇 😉

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store