Thanks for explaining @fool – that’s really interesting, and unexpected! I’ve confirmed now that when I allow the builds to having via github webhooks (eg, branch deploys or master updates) then the prefixed GATSBY_ magic substitution happen as expected.
Is there a way I can leverage the Netlify CI builds when using netlify deploy to test deploys of WIP code? I guess I expected this would work because I have a build command defined in my netlify.toml which leads to a gatsby build, but now I think this may be irrelevant.
edit: Hmm as an update, I’ve discovered that process.env.DEPLOY_URL is undefined in a PR preview deploy, from the context of a function. Hmm this I’m less sure how to work around.
I’m using Gatsby and know that my build command is gatsby build. I’ve declared my variables in the Netlify UI so I don’t really care about confirming they are showing up in my console or how to do that.
What I would like is to fix the problem of my environmental variables showing undefined after I’ve built and deployed my site.
I understand that build time and run time are two different animals: that build time is basically distilling and packaging all your pages and their dependencies/assets into files that can be digested by the browser; run time being what the browser does with those files, functions/directives, etc., and that the environmental variables need to baked into the code so that the browser has access to it and so that it is not undefined.
That now has me wondering if that isn’t inherently a security concern?
I guess what I’m really wondering is if there’s an alternative to using Netlify’s serverless functions to run code that uses predeclared environmental variables?
@bencao’s plugin is a great way to automate this! But your concerns are well placed - if you can’t share your environment variables with the general public in your page source code, you absolutely don’t want to publish them here!
I’m having difficulty narrowing down where to adjust my build. I have deployed a basic jamstack and set up an API key in environment variables via Netlify UI. Where and how do I tell my build where to expect the secret? There are so many avenues for this and I can’t seem to hunker down on an appropriate path for my basic html, css and js deploy. Thanks!
Maybe I’m doing something strange, but I’ve set a toml file in my root with a setting
[context.producton]
NODE_ENV = staging
[context.staging]
NODE_ENV = staging
Just to test some settings. This isn’t being taken into account and each deploy on either my staging or master branch is being given a production flag
I’ve also used the UI, and this flag is being disregarded. Would love to understand what I need to change to make this happen
Sorry for the slow response! I see you shared this question about 8 days ago. Are you still encountering this issue? If so, please let me know what else you have tried in the interim!
Thanks for getting back to me. I just had time this morning to test this out. I still see the same behavior. I still must be doing something wrong. My toml file not reads
The deploy ID is 605df7c7dce07100078de3eb which ties back to my staging branch in github.
I typically work in yaml and not toml. Is there syntax specific things I need to take into account that I could be missing? For example, spaces vs tabs / only 2 spaces and I’m giving it 4? Things like that.