I’m trying to deploy my latest production branch “main”, but is being canceled.
Problem:
- Current: The
VERCEL_GIT_COMMIT_REF
environment variable is empty within the bash script executed during the Vercel build process. As a result, the script always evaluates to theelse
condition, canceling the build. - Expected: The
VERCEL_GIT_COMMIT_REF
environment variable should contain the name of the Git branch associated with the Vercel deployment (e.g., “staging”, “main”). The script should then allow the build to proceed when the branch is “staging” or “main”, and cancel it otherwise.
Code:
#!/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
Project Information:
- Framework: Next.js 15.2.0
- Environment: Vercel
- Project Settings: The “Ignored Build Step” is set to execute the provided bash script (
vercel-bash-script.sh
). The specific command being run isbash vercel-bash-script.sh
.