5

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".

Máté Antal
  • 157
  • 1
  • 21

2 Answers2

1

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);
}
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0
  1. Navigate to your project settings: https://vercel.com/user/slug/settings/git

  2. Update the build ignore step to "custom" and enter:

[ "$VERCEL_GIT_COMMIT_AUTHOR_LOGIN" == "dependabot[bot]" ]

image of the above steps

Android
  • 1,230
  • 12
  • 20