How do I use the "Ignored Build Step" field on Vercel?

Instructions on how to use the "Ignored Build Step" field to programmatically prevent a new deployment from being built.
Last updated on August 28, 2024
Build, Deployment & Git

You can enable the "Ignored Build Step" field by referring to the documentation of this feature. If the command returns "0", the build will be skipped. If, however, a code "1" or greater is returned, then a new deployment will be built.

One of the most important aspects of this feature is to understand how Vercel clones your code. The platform performs a "shallow clone" with the command git clone --depth=10 (...), to fetch ten levels of git commit history.

To run a bash script in the "Ignored Build Step", you need to set the following in the field: bash script.sh. Do notice the file should exist in your repository. An example of a bash script:

Note: You can also use Node scripts (e.g. node ignore-step.js).

#!/bin/bash
echo "VERCEL_ENV: $VERCEL_ENV"
if [[ "$VERCEL_ENV" == "production" ]] ; then
# Proceed with the build
echo "✅ - Build can proceed"
exit 1;
else
# Don't build
echo "🛑 - Build cancelled"
exit 0;
fi
An example Ignored Build Step script where only commits made to the production environment are allowed to be deployed. The environment variable "VERCEL_ENV" should be added to your project.

By using this command, Vercel will only build deployments when the value of "VERCEL_ENV" is "production". That variables was added to the Environment Variables UI which makes it available for the project.

You can create a command referencing System Environment Variables directly in the Ignored Build Step field:

if [ "$VERCEL_ENV" == "production" ]; then exit 1; else exit 0; fi
An example Ignored Build Step command where only commits made to the production environment are allowed to be deployed.

Below is an example script that will conditionally build certain branches:

#!/bin/bash
echo "VERCEL_GIT_COMMIT_REF: $VERCEL_GIT_COMMIT_REF"
if [[ "$VERCEL_GIT_COMMIT_REF" == "staging" || "$VERCEL_GIT_COMMIT_REF" == "main" ]] ; then
# Proceed with the build
echo "✅ - Build can proceed"
exit 1;
else
# Don't build
echo "🛑 - Build cancelled"
exit 0;
fi
An example Ignored Build Step command where only commits made from the branches "main" and "staging" are allowed to be deployed.

Before you proceed, keep in mind the Ignored Build Step runs in the same folder your selected "Root Directory". Therefore, you may need to adjust it slightly so it can fit your needs. To build a new deployment considering only a certain folder, you can use the following command:

git diff HEAD^ HEAD --quiet -- ./packages/frontend/
An example of "Ignored Build Step" command. If changes were commited to "./packages/frontend/", the command will yield a non-empty response, allowing the build to proceed.

By using this command, Vercel will only build deployments when changes are made inside of the packages/frontend/ directory. If the folder ./packages/frontend/ is your selected "Root Directory", then you can use:

git diff HEAD^ HEAD --quiet -- .
An example of "Ignored Build Step" command. If changes were commited to ".", the command will yield a non-empty response, allowing the build to proceed.

You can also access other folders in your deployment to check for changes. If you are building your frontend with packages/web selected as your "Root Directory", and your app must be deployed only when changes to ../../packages/docs are made, you can use:

git diff HEAD^ HEAD --quiet -- ../../packages/docs
An example of "Ignored Build Step" command. If changes were commited to "../../packages/docs", the command will yield a non-empty response, allowing the build to proceed.

Vercel can now automatically skip builds for unchanged code in certain monorepo projects. If you don't require as much granularity, such as skipping based on branch names for example, then you may be able to make use of this option to optimize your deployment queue.

When this option is enabled, projects without changes in their source code (or the source code of internal dependencies) will be skipped, reducing build queuing and improving the time to deployment for affected projects. This feature is powered by Turborepo, and works with any monorepo using workspaces.

Learn more about skipping unaffected projects.

The first thing to check is if your command uses Vercel related variables such as `VERCEL_ENV`. You can check this either in your custom script or if you use a preset option then it will show what command is run in the `Ignored Build Step` settings once this is selected. If you are using these variables, make sure you have checked the option to `Automatically Expose System Environment Variables` so that these are available to the command.

To debug the Ignored Build Step commands locally, it is important to first use a folder that can replicate the setup available on Vercel. To do this, you can apply the following steps:

  1. Clone the repository to another folder using git clone --depth=10 (...).
  2. Run the command or script in your terminal.
  3. You can check the exit code returned by the last command with echo $?.

Couldn't find the guide you need?