简体   繁体   English

如何在travis-ci中设置环境变量并从python脚本访问它们?

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

Our travis.yml looks like this: 我们的travis.yml看起来像这样:

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 the python script with the tests, the line 然后在带有测试的python脚本中,行

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

throws an error (shortened): 抛出错误(缩短):

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

This error only occurs on travis . 此错误仅发生在travis上 If we run them locally, it works without a problem. 如果我们在本地运行它,它的工作没有问题。 So we assume we set the environment variable MONGO_URL in a wrong way. 所以我们假设我们以错误的方式设置环境变量MONGO_URL We already tried ommitting the quotation marks, but it did not help. 我们已经尝试过省略引号,但它没有帮助。

Any hints? 任何提示? We use the free cloud service of travis-ci . 我们使用travis-ci的免费云服务。

It works perfectly fine now, the error was that I accidently created another travis.yml missing the . 它现在完全正常,错误是我意外地创建了另一个travis.yml错过了. in front of it - so the actually executed .travis.yml did not contain the environment variables. 在它前面 - 所以实际执行的.travis.yml不包含环境变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM