iTranslated by AI
Ignoring Preview Deployments for Specific Branches on Vercel
Old content
When you link a GitHub repository to a Vercel project, a preview deployment is created every time you push to any branch. While this is a very convenient feature, frequent pushing can make you worry about hitting limits.
As of March 2021, restricting these preview deployments to specific branches is somewhat complicated. Since there seems to be high demand for this, it might be supported in the future. For the latest information, it's best to check the following issue.
How to ignore preview deployments for branches other than specific ones
You will need to use something called "Ignored Build Step". The Zenn development members did this for us. You can get it working by following this scrap.
1. Place a shell script in your project
As an example, let's say you want to perform a preview deployment only when a push is made to the develop branch (or when a PR is merged). First, create a file such as vercel-ignore-build-step.sh with the following content.
#!/bin/bash
echo "VERCEL_GIT_COMMIT_REF: $VERCEL_GIT_COMMIT_REF"
if [[ "$VERCEL_GIT_COMMIT_REF" == "develop" ]] ; then
# Proceed with the build
echo "✅ - Build can proceed"
exit 1;
else
# Don't build
echo "🛑 - Build cancelled"
exit 0;
fi
2. Configure Ignored Build Step in Vercel Dashboard
Open your project on the Vercel dashboard and navigate to the [Git] menu. In the [Ignored Build Step] section, you can specify a COMMAND to execute the file you created. If you placed vercel-ignore-build-step.sh in the project root, it should look like this:
bash vercel-ignore-build-step.sh
Specify it like this
Settings are now complete. Except when a push is made to the target branch, you will see that it has been cancelled as shown here.
Removing this display seems difficult at the moment...
Extra) How to turn off Vercel Bot comments on Pull Requests
By default, the Vercel Bot is set up to comment on PRs. If you want to turn this off, open vercel.json in your project root (create it if it doesn't exist) and set the value of github.silent to true.
{
"github": {
"silent": true
}
}
👇 Check the comment for the latest method
Discussion
古い記事ですが「Vercel branch ignore」などの検索ワードでトップに表示されるのでコメントします。
今は Vercel で特定のブランチ名でデプロイする or しないを決めるもっと簡単な方法があります。
vercel.json で
git.deploymentEnabledにブランチ名マッチングルールを指定することで、ブランチへのプッシュでデプロイされるかどうかを決められます。参考になれば幸いです。ありがとうございます!記事も修正しました!