Nanor
Nanor

Reputation: 2550

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.

Upvotes: 4

Views: 1694

Answers (1)

dopstar
dopstar

Reputation: 1488

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

Upvotes: 0

Related Questions