Unable to access environment variables in Travis CI


This is my first time using the Travis CI tool or any CI/CD tool.

I am using my .travis.yml file to run some unit tests I have written which require my Mongo URI which is stored in my environment variable (.env file).

I read the documentation on how to encrypt private environment variables (travis-ci.com) and followed everything.

My tests pass locally but on the Travis CI pipeline, it is unable to access the environment variable which I have encrypted, which is my Mongo URI.

This is what my .travis.yml file looks like

language: node_js
node_js: 17.4.0
  - secure: encrypted_token
- echo '*******Build starts********'
- echo 'Installing dependencies'
- npm install
- echo 'Running tests'
- npm test

I’d appreciate some help. Thanks.


Once you encrypt the environment variable you will need to access like echo $foo notation. Travis CI is not using the .env file that you have in your repository.

Travis CI Staff