Access environment variable set up in circleci project in the application

109 Views Asked by At

I have set up an environment variable in the circle ci project like this. I am trying to access it in a js file. So I exported the variable in circle ci yaml file like this:


    jobs:
      build:
        ...
        steps:
          - run: 
              command: |
              echo 'export ENV_VAR="$ENV_VAR"' >> "$BASH_ENV"
                source "$BASH_ENV"

And I am trying to access in a js file as process.env.ENV_VAR but I am getting undefined.

2

There are 2 best solutions below

0
athi On BEST ANSWER

All custom variables you need to access in a js file should be named with the prefix REACT_APP_ For more info, this link can be referred to.

1
Bhavesh Parvatkar On

You are setting that env only for that step. That env will be lost once this step is finished and the next steps won't be able to access it. Based on your use case you should configure the env, the doc has mentioned the support for project level, job level and even container level. Prefer Project level if possible, it's easy to set up.