简体   繁体   English

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

[英]Python code not reading Travis CI environment variables

I've added a environment variable to my Travis CI repository under the name SECRET_KEY as described in this guide. 我已经在我的Travis CI存储库中添加了一个环境变量,名称为SECRET_KEY ,如指南中所述。 When I deploy to GitHub and the git hook signals Travis and Travis then runs, I get a KeyError in the line: 当我部署到GitHub并且git挂钩信号Travis和Travis然后运行时,我得到了一行KeyError

SECRET_KEY = os.environ['SECRET_KEY']

Why is it not recognising the key? 为什么不识别钥匙?

Edit 编辑

After following advice in the comments to add export SECRET_KEY=$SECRET_KEY to the .travis.yml file I get the error django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty. 按照注释中的建议将export SECRET_KEY=$SECRET_KEY添加到.travis.yml文件后,我收到错误django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.

My .travis.yml file looks like this: 我的.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>

The secure parameter refers to this guide which I first tried to no avail. secure参数是指我最初尝试无效的指南。

Change your travis file to define the secure encrypted key under env.global section as follows: 更改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

Where secure: <long encrypted string> corresponds to your $SECRET_KEY that you generated with travis encrypt 'SECRET_KEY=this-is-demo-password' --add secure: <long encrypted string>对应于您使用travis encrypt 'SECRET_KEY=this-is-demo-password' --add生成的$SECRET_KEY travis encrypt 'SECRET_KEY=this-is-demo-password' --add

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

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