Python代码没有读取Travis CI环境变量

时间:2015-11-18 17:25:33

标签: python travis-ci

我已根据this指南中所述的名称SECRET_KEY向我的Travis CI存储库添加了一个环境变量。当我部署到GitHub并且git挂钩信号Travis和Travis然后运行时,我在行中得到KeyError

SECRET_KEY = os.environ['SECRET_KEY']

为什么不识别钥匙?

修改

根据评论中的建议将export SECRET_KEY=$SECRET_KEY添加到.travis.yml文件后,我收到错误django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.

我的.travis.yml文件如下所示:

language: python
python:
    - "2.7"

install: pip install -r requirements.txt

script:
    - export SECRET_KEY=$SECRET_KEY
    - python manage.py test

secure: <long encrypted string>

secure参数指的是this指南,我首先尝试无效。

1 个答案:

答案 0 :(得分:0)

更改您的travis文件,以在env.global部分下定义安全加密密钥,如下所示:

language: python
python:
    - "2.7"

install: pip install -r requirements.txt
env:
  global:
      secure: <long encrypted string>

script:
    - export SECRET_KEY=$SECRET_KEY
    - python manage.py test

secure: <long encrypted string>对应于您使用$SECRET_KEY生成的travis encrypt 'SECRET_KEY=this-is-demo-password' --add

相关问题