首页 > 解决方案 > 如何防止对 main 的提交部署在 vercel 上

问题描述

我想知道是否有办法阻止 Vercel 部署直接提交以自动部署到生产环境。我不介意每次都必须单击一个额外的按钮——这可能吗?我看到了Ignored Build Step文档,但我真的不明白如何使用它,或者它是否是正确的使用方法。

标签: githubvercel

解决方案


如果要使用 Ignored Build Step 功能,请执行以下操作

  • 在您的存储库中创建一个script.sh文件:
#!/bin/bash

if [[ "$VERCEL_GIT_COMMIT_REF" == "main"  ]] ; then
  # Don't build
  echo " - Build cancelled"
  exit 0;

else
  # Proceed with the build
    echo "✅ - Build can proceed"
  exit 1;
fi

在您的 Vercel Dashboard 中,转到您的项目设置 > Git > Ignored Build Step,并在字段中写入 <code>bash script.sh。


推荐阅读