bashgitgithubdeploymentvercel

Stop Vercel preview deployments on Dependabot PRs


I want to stop Vercel from creating preview deployments for the dependabot pull requests.

In Vercel, in the Ignored Build Step I've tried this:

bash vercel.sh

and in my repo, the vercel.sh file looks like this:

#!/bin/bash

echo "VERCEL_ENV: $VERCEL_ENV"

# check branch name
BRANCH=$(git rev-parse --abbrev-ref HEAD)
echo "BRANCH: $BRANCH"

# check if branch name does not contain "Bump" (every dependabot PR starts with this)
if [[ $BRANCH != *"Bump"* ]]; then
  exit 1
fi

exit 0

What am I missing? The deployment still went through.

Also tried writing this right to the Ignored Build Step

if [ "$VERCEL_GIT_COMMIT_AUTHOR_LOGIN" == "dependabot" ]; then exit 0; else exit 1; fi

Still created the deployment.

Tried it this way too

if (process.env.VERCEL_GIT_COMMIT_AUTHOR_LOGIN === "dependabot") {
  process.exit(0);
} else {
  process. Exit(1);
}

and then calling it like node ignore-nuild.js in the Ignored Build Step, but this didn't help either.

Update

My bad, it was "dependabot[bot]", not just "dependabot".


Solution

  • First, always surround with quotes a variable you want to echo. That way, you can catch the invisible space which might plague its value:

    echo "BRANCH: '${BRANCH}'"
                 ^^^       ^^^
    

    Second, you can add echo before the exit, to differentiate when you exit 1 from exit 0.

    echo "continue"
    exit 0
    

    Third, you can try, for testing:

    if [[ "${BRANCH#Bump}" != "${BRANCH}" ]]; then ...
    

    If $BRANCH starts with Bump, then the condition will be true.


    The OP suggests:

    if (process.env.VERCEL_GIT_COMMIT_AUTHOR_LOGIN === "dependabot[bot]") {
      process.exit(0);
    } else {
      process. Exit(1);
    }