[Github integration] First PR deploy has no PR ID

Hello Community,

We are using the Github integration to deploy preview environments.

Our app consist of a backend and a frontend, the latter being deployed by Vercel.

The URL of the backend being deterministic (e.g. https://pr-${PR_ID}.my-backend.com), we use the process.env.VERCEL_GIT_PULL_REQUEST_ID in the frontend to know where to look for the backend.

This behavior works for PR on which we iterate, but the very first deployment - right after pushing the branch and creating the PR - does not have the PR ID. Any deployments happening after that (by pushing a new commit) deploys the environment correctly and includes the PR ID.

We tried using the “Ignore Build Step” feature with the following, but the result is that the first deployment (when creating the PR) is simply skipped, creating the PR does not deploy anything:

[ "$VERCEL_GIT_COMMIT_REF" == "main" ] || [ -n "$VERCEL_GIT_PULL_REQUEST_ID" ] && exit 1 || exit 0

Is there a way to force a redeploy when the PR is created?


Steps to reproduce:

  • Enabled Github integration and preview builds
  • Create new branch and some commit
  • Push to remote branch
  • Create PR

Expected result:

  • The initial (branch) deployment is updated (as a PR deployment) with $VERCEL_GIT_PULL_REQUEST_ID set

Actual result:

  • The (branch) deployment is not updated, $VERCEL_GIT_PULL_REQUEST_ID is empty
  • We need to push another commit to force a redeployment and have the PR ID available

Hey @samgroot. It looks like this is expected behavior for the VERCEL_GIT_PULL_REQUEST_ID system environment variable.

If a deployment is created on a branch before a pull request is made, this value will be an empty string.

Vercel creates deployments on git push so the PR won’t exist on the first push to a new branch. After the PR is created, subsequent pushes to that branch will include the PR ID. So you could open a PR and then push the commit to make sure the variable has the PR ID value set. Or you could use GitHub Actions to deploy with a more customized workflow tailored to your app architecture.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.