`VERCEL_GIT_PREVIOUS_SHA` is always empty

I am building a blog and wanted to add a build step to notify when a new post is added. The script checks for any posts added between VERCEL_GIT_PREVIOUS_SHA and the building commit.

const currentSha = env.VERCEL_GIT_COMMIT_SHA;
const previousSha = env.VERCEL_GIT_PREVIOUS_SHA;

if (!currentSha || !previousSha) {
  log(`skip: missing SHA (current=${currentSha ?? "unset"}, previous=${previousSha ?? "unset"})`);
  process.exit(0);
}

Unfortunately, even on the main branch that has been deployed multiple times this fails:

[notify-on-publish] skip: missing SHA (current=360751584f5a2db35960b8d9c32770e5b14f17ee, previous=)

example deploy: https://vercel.com/discorevs-projects/sanedev/8HUHcS52C3UVfgtsmapb6mxAQUJQ

The help AI was helpful, until it wasn’t:

I can see the issue now. Looking at your deployment history for the main branch, I can confirm there are multiple successful production deployments. Let me check one more thing about the project configuration:

I can see that your project has autoExposeSystemEnvs: true, which means system environment variables should be exposed. You also have multiple successful production deployments on the main branch.

This appears to be a bug or unexpected behavior with how VERCEL_GIT_PREVIOUS_SHA is being populated. Based on your deployment history, there are clearly previous successful deployments on main that should be providing the previous SHA.

What I found:

* Your latest deployment (360751584f...) should have referenced the previous deployment (b6a2dcd2a9...) as the previous SHA
* System environment variables are correctly enabled (autoExposeSystemEnvs: true)
* All your recent main deployments are from Git pushes (not redeployments), so the Git context should be available

This looks like it may be a platform issue rather than a configuration problem on your end. Let me check if you're eligible to create a support case so our team can investigate why VERCEL_GIT_PREVIOUS_SHA isn't being populated correctly for your project.

Good news — you're eligible to create a support case for this. This does appear to be unexpected behavior that our team should investigate further.

Summary of the issue:

* VERCEL_GIT_PREVIOUS_SHA is empty on main branch deployments despite multiple previous successful deployments existing
* System environment variables are enabled
* Deployments are triggered via Git (not manual redeployments)
* The variable should be populated but isn't

On the hobby plan you are not eligible to create a support case. (the AI being wrong is a separate issue, it’s just included to show that the issue was also triaged by the AI which agrees it’s a support issue).

Hi @discorev, welcome to the Vercel Community!

I’m sorry that you’re facing this issue. Could you please share your public repo or a minimal reproducible example. That will let us all work together from the same code to figure out what’s going wrong.

first deployment: https://vercel.com/discorevs-projects/vercel-debug/2sAQN5ycpEAkuXVo7aBz1PrFk6Z9 (done without the script referencing the environment variable to as closely replicate the situation of my real project)

Second deployment: https://vercel.com/discorevs-projects/vercel-debug/7tWjECcCxLfgaDsFEpKFQ1nXpoBL

This deployment included vercel-debug/scripts/check-previous-sha.mjs at main · discorev/vercel-debug · GitHub

and reproduces the log line

[check-previous-sha] skip: missing SHA (current=047d485606c49cb87df611112a6d8b391c070827, previous=)

@anshumanb is there any update on this or any other information I can share that would be helpful?

Kind Regards,
Ollie

Hi @discorev, I’m sorry, this one took longer than I thought.

This env var is only supplied if an ignored build step is set in the projects git settings. Otherwise, it will not be set. A workaround is to add

"ignoreCommand": "exit 1"

To your vercel.json. This should allow for the variable to then be defined for you in your script. An ignoreCommand that always exits 1 tells Vercel “don’t skip, always build”, which ensures your vercel.sh script runs on every commit and all the git-related env vars are recomputed each time. From there you can diff the current SHA against whatever you persist as the last convex deploy SHA in your script.

Can you add that line and let me know if it works?

If it solves your issue, I’ll update the docs.

Hey,

Thank you - that does appear to solve it, I’ve applied it on both the public debug solution and my private repo and both are working :slight_smile:

Hi @discorev, thanks to your post, we’ve updated the docs to reflect this requirement correctly.