I know I can use the netlify.toml file to create context-specific overrides for environment variables, but what do I do if I want to use the UI to keep the variables out of version control? I would like to be able to save variables with the CLI and/or the UI for specific deploy contexts such as “staging”.
You can use a
suffix for your env vars, then implement any system that lets you either define which set to use or aliases them back to non prefix/suffix values.
STAGING_KEY1 = 'abc123' STAGING_KEY2 = 'def456' STAGING_KEY3 = 'ghi789' LIVE_KEY1 = 'abcabc' LIVE_KEY2 = 'defdef' LIVE_KEY3 = 'ghighi'
Here’s a plugin that uses this method:
Looks like Netlify just released a feature to address this:
Thank you for passing along the feature announcement, @nathanmartin! Perfect timing, huh?
Wanted thing I wanted to mention, @milesingrams, in case you need branch-deploy-specific values:
The initial beta we announced includes the ability to set values to 4 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! Just wanted to call that out in case you try out the beta and it’s not quite what you need yet.
Thanks to both and always happy to get your feedback!