简体   繁体   中英

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. When I deploy to GitHub and the git hook signals Travis and Travis then runs, I get a KeyError in the line:

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.

My .travis.yml file looks like this:

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.

Change your travis file to define the secure encrypted key under env.global section as follows:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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