How to set environment variables in travis-ci and access them from python script?

Our travis.yml as follows:

 language: python python: - "2.7" env: - "MONGO_URL=mongodb://localhost/" services: mongodb # command to install dependencies install: "pip install -r requirements.txt" # command to run tests script: nosetests 

Then in python script with tests line

 server.connect(os.environ['MONGO_URL']) 

gives an error (in abbreviated form):

 File "/home/travis/virtualenv/python2.7/lib/python2.7/UserDict.py", line 23, in __getitem__ raise KeyError(key) 

This error occurs only on travis. If we run them locally, this works without problems. Therefore, we assume that we have set the environment variable MONGO_URL . We already tried quotation marks, but that didn't help.

Any clues? We use the free cloud service travis-ci.

+6
source share
1 answer

Now it works fine, the error was that I accidentally created another travis.yml missing . in front of it - so the .travis.yml actually executed .travis.yml not contain environment variables.

+4
source

All Articles