Hi Netlify.
I’m having an issue with accessing the COMMIT_REF in my Gatsby project to initialise a release to Sentry.
In .env.production file I set a variable GATSBY_COMMIT_REF=$COMMIT_REF
then in my main Layout.jsx
component I do console log the value like this console.log('Website', { sentryRelease: process.env.GATSBY_COMMIT_REF })
and in the build process I can see that instead of the reference ID of the last commit the string value is console logged.
2:23:30 PM: Website { sentryRelease: '$COMMIT_REF' }
I’m using the same function to initialise a release to a Sentry in couple of other CRA projects where it works without any issues like this: REACT_APP_COMMIT_REF=$COMMIT_REF
HI there, @nord
Can you share your site name and your repo with us? That would help us dig into this further. Thank you!
Hi @hillary,
Our site name is nord-website
and our repository is private so I can’t share it with you.
Thanks in forward!
Hi @hillary,
Is there any update on this issue?
Thank you.
Hey there, @nord
Apologies for the delay here, I appreciate you following up.
I brought this up to our Gatsby pro and they are suggesting the following: what if you try "build": "GATSBY_COMMIT_REF=$COMMIT_REF npm run build"
rather than setting the environment variable to GATSBY_COMMIT_REF=$COMMIT_REF
The problem is that the env var isn’t being expanded as it’s currently declared because .env.
files don’t handle env var expansion. Moving this outside of .env
to the build script will work around that.
Thanks again for following up, and please let us know if this gets you sorted out!