[英]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.