skip to Main Content

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

Answers


  1. Chosen as 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.


  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search