cball / netlify-plugin-contextual-env

A Netlify plugin to override ENV vars based on a branch or context
56 stars 13 forks source link

This does not work unless context-free environment variables are set #13

Open ehmicky opened 3 years ago

ehmicky commented 3 years ago

If a site has an environment variable PRODUCTION_TEST, the variable will not be used, even if the branch is production, unless a TEST environment variable also exists (which might not be the case).

adstr123 commented 3 years ago

I found this issue when I was trying to figure out why my build failed. If this is intentional behaviour, then that's not clear at all.

My specific example was that I had 5 ENV vars total:

CONTENTFUL_SPACE_ID
MASTER_CONTENTFUL_ACCESS_TOKEN
MASTER_CONTENTFUL_ENVIRONMENT_ID
DEV_CONTENTFUL_ACCESS_TOKEN
DEV_CONTENTFUL_ENVIRONMENT_ID

I thought that I had to name them that way since I wanted to differentiate CONTENTFUL_ENVIRONMENT_ID and CONTENTFUL_ACCESS_TOKEN based on branch, but now I have renamed the two MASTER variants to remove that branch name, its fine. 🤷

princefishthrower commented 3 years ago

@adstr123 - do you mean you had to ADD the MASTER_ in to get it to work? Or remove it?

I'm having similar troubles, I'm using the 'suffix' mode for my staging branch, but none of my _STAGING environment variables seems to be injected into my staging environment.

adstr123 commented 3 years ago

@princefishthrower I had to remove it. I expected to have to put it in there. I'm not sure if this was just my intuition, or if I was swayed that way by the readme - which gives an example of a productioncontext, which I equated to a master branch...

princefishthrower commented 3 years ago

I looked into this further. It turns out that even though I had the plugin in my package.json and also in my netlify.toml as this plugin's README shows, the plugin only started working after activating it in the project's plugin section - which I thought was weird. I'm still trying to figure out when the netlify.toml settings are actually applied or overridden from other settings set in the UI.

Anyway, I also agree the documentation could be a bit more clear. Something as simple as a sentence like 'for master or production contexts, no context name is needed as a part of the environment variable'.