How to update Environment Variables?

Hi,

I was already using environment variables in my app for values that quite never change.
I wanted to use environment variables for feature flags. But I realise that if I change a value using the CLI, it does not change in my app. I have to deploy the app to see the change. Is it the expected behaviour?

Thanks for your help!

https://developer.atlassian.com/platform/forge/environments-and-versions/#environment-variables
https://developer.atlassian.com/platform/forge/cli-reference/variables/

1 Like

@BertrandDrouhard1,

Yes, I confirm that’s the expected behavior. I think you would need to invest in a real feature flag system for that kind of switching.

@ibuchanan please can you get the docs updated to reflect clearly that environment variable changes do not take effect until the app is redeployed?

We had a production incident earlier because we were setting environment variables in our CI/CD pipeline after deployment and it took quite some investigation to figure out that forge variables list was showing us a different set of variables than what the app itself could see.

2 Likes

@jbevan,

Can you elaborate? What switches were you using for the CLI for both setting and listing?

We merged the following code:

export const getEnvVariable = (name: string, logger?: Logger): string | undefined => {
    const key = process.env[name];
    if (key === undefined) {
        const message = `Environment variable ${name} is not provided`;
        logger ? logger.error(message) : Logger.consoleError(message);
    }
    if (!key) {
        const message = `Environment variable ${name} is falsey`;
        logger ? logger.error(message) : Logger.consoleError(message);
    }
    return key;
};

const superSecret = getEnvVariable("SUPER_SECRET");

Our build pipeline did this:

npx forge deploy --environment production --non-interactive --no-verify --verbose
npx forge variables set --encrypt SUPER_SECRET "shhhh" --environment production

and then we got the following error all over the app logs:

Environment variable SUPER_SECRET is not provided

and when we ran:

forge variables list --environment production

we could see the SUPER_SECRET variable was definitely defined.

Redeploying the app solved the problems.

3 Likes

@jbevan,

Please watch, vote, and comment on FRGE-943 which I reopened based on your case.