DEV Community

Discussion on: May the Log Be With You

Collapse
 
sakhmedbayev profile image
sakhmedbayev

Not quite understand this part:

release: <% COMMIT_HASH %>
Enter fullscreen mode Exit fullscreen mode

How can it be set exactly in JS/next.js projects?

Collapse
 
dfjs profile image
Darren Shewry

Yes good question, the author hasn't mentioned the templating system they're using here or how they've put exposed commit hash as an environment variable.

But for most JS/Next.js projects to use environment variables would use process.env like so:

release: process.env.COMMIT_HASH
Enter fullscreen mode Exit fullscreen mode

Or, because this would be directly exposed to the client-side (i.e. public), like this with Next.js:

release: process.env.NEXT_PUBLIC_COMMIT_HASH
Enter fullscreen mode Exit fullscreen mode

Reference: nextjs.org/docs/basic-features/env...

Note that the Amplify build environment exposes the git commit hash for you by default. So if you need use that env var locally, you'll need to get the actual git commit hash, and then expose it as an env var yourself (for consistency perhaps), which is another story... e.g. javascript.plainenglish.io/passing...