How to get environment variables?

I am storing certain sensitive data in environment variables in CircleCI’s project settings. How do I add them to my circle.yml file? I tried the following, but it doesn’t work:

    version: 3.5.1

Is this how I’m supposed to define environment variables so that CircleCI gets them from the project settings?

Those last two lines aren’t needed here. You’d just use $CLIENT_ID or ${CLIENT_ID} in circle.yml where it’s needed. The’d also be available in scripts called via circle.yml.

This is assuming that $CLIENT_ID and $CLIENT_SECRET were configured as Environment Variables via CircleCI’s UI or API.

These variables are needed to run my tests. I have defined them in our project settings through CircleCI’s UI. I tried defining those variables in my circle.yml file because my tests cannot find those variables. Circle CI’s build page says that it is exporting those variables:

Exporting CLIENT_ID

Why can’t my tests find them?

1 Like

Hey aderhg, Did you ever solve this issue? I think I am running into the same thing. My Mocha tests can’t read ENV variables I have set through the Circle CI UI.

Some questions:

Mocha is running as the same user correct?
Is this running within Docker?
This is about CircleCI 1.0?
Are you using the right capitalization for the variables?
Are you storing non-ASCII characters in the variables?
Also, maybe this?

1 Like


Thanks for the reply.

  • I believe Mocha is running as the same user. How can I check this? I have done nothing that would lead me to believe this is not the case
  • This is not running within Docker
  • I think this is CircleCI 2.0
  • I am using the correct capitalization for the variables
  • I am not storing non-ASCII characters in the variables

I checked the link you provided, but am still confused.

In my app.js I have this:

if (process.env.NODE_ENV !== 'production') {

I guess my question is why when in my test:

const authToken = process.env.AUTH_TOKEN

process.env.AUTH_TOKEN is not found when run by CircleCI?

Do these env variables need to be imported via the circle.yml file first and then retrieved from there?
Would I need to do something like this in my circle.yml file:


Please forgive my confusion and thank you again.


Hi, did you ever fingure this out?

1 Like