Unable to access environment variables in Travis CI

Hi,

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
env:
  global:
  - secure: encrypted_token
script:
- echo '*******Build starts********'
- echo 'Installing dependencies'
- npm install
- echo 'Running tests'
- npm test

I’d appreciate some help. Thanks.

Hey,

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.

Thanks,
Mustafa
Travis CI Staff