app router “next”: “15.1.3” , using vercel project
Vercel Staff
THe above steps should do the ticket. Are you reading commit SHA in source code (runtime) or during build (build step)? You can replace buildCommand with echo $VERCEL_GIT_COMMIT_SHA && npm run build or similar to figure out if the env var indeed available or not
Yes, I can see variable $VERCEL_GIT_COMMIT_SHA when I echo it in the vercel build command.
How do I access the variable in my client side code(example Page.tsx )?
Vercel Staff
Environment variables are by default only available on the server side. To access Vercel's system environment variables like VERCEL_GIT_COMMIT_SHA on the client side, you need to follow a specific approach.
Option 1: Expose it with NEXT_PUBLIC prefix
You'll need to create a new environment variable that's prefixed with NEXT_PUBLIC_ and assign the value of VERCEL_GIT_COMMIT_SHA to it. This can be done in your project settings or build configuration.
Can you share some vercel build command examples ?
Thsnks, Peter
hi Swarnava, using process.env.VERCEL_GIT_COMMIT_SHA locally returns a hash that is not match last commit
a) git rev-parse origin/main 37d9d82e9f27ae2a7694cec9a83e8c3ac1afc6b9 vs
b) 112233445566
vercel cli - this does not populate the project env variable - not sure why ??
npx convex deploy --cmd 'set NEXT_PUBLIC_GIT_COMMIT_SHA = $VERCEL_GIT_COMMIT_SHA && npm run build'
githubCommitRef=“feature/branch-name” <-What does feature mean ?
My repo is zork0 , and I have 2 branches : master and main
I tried : vercel --prod -m githubDeployment="1" -m githubCommitRef="zork0/main" but l do not work
Here is my vercel build command:
npx convex deploy --cmd 'set NEXT_PUBLIC_GIT_COMMIT_SHA = $VERCEL_GIT_COMMIT_SHA && npm run build'
Thanks,Peter
Vercel Staff
That's branch name.
it should be githubCommitRef=“main”
hi Swarnava,,
Can you find my mistake ?
I deployed like : >vercel --prod -m githubDeployment="1" -m githubCommitRef="main"
NEXT_PUBLIC_GIT_COMMIT_SHA = "git commit hash" <-- This is the environ. variable - but it never changed.