How to programmatically cancel a Netlify build


Sometimes you've got a build script for a Netlify site, and want to cancel the build and deploy if a certain condition is true a version of the website with an error doesn't get published.

To cancel the build in a Node.js script, just run:


This causes the build to fail, and will show a message like this in your Netlify build logs:

If you want to add additional information on why the build failed, log a message before calling process.exit:

console.warn('This is what went wrong.')

This page is referenced in: Coding Blog