I am wanting to set deploy context-specific environment variable overrides that are secrets (e.g. API_KEY) so I don’t want to hardcode them in the netlify.toml file.
Is there a way to set Deploy context-specific environment variables via the UI or API to avoid hard-coding them?
In your code, you can do something like:
let secret = process.env.CONTEXT === 'foo' ? process.env.SECRET1 : process.env.SECRET2
Here’s a more detailed example: How to Contextualize your env vars with Netlify Build Plugins
Hi @ryanbluden, I wanted to share an update in case it helps! We recently introduced support for scopes and deploy contexts for environment variables. This beta enables you to set contextual values, or limit environment variables to specific scopes, directly from the Netlify app UI. netlify.toml
configuration would no longer be needed.
The initial beta includes a few basic deploy contexts: production, Deploy Previews, all branch deploys, and local development (Netlify CLI). We know that branch-deploy-specific values are important to a lot of folks, so we plan to add that to the beta very soon. Hope this helps and happy to answer any questions!