4π
β
I got my answer thanks to @Zeitounator
I will simply quote his/her comment in order to make it simple:
os.environ.get
retrieves environment variables from the running system which is your docker container, not from the underlying gitlab-ci system. Gitlab CI vars (as your usual shell vars) are not automagically pushed to your container.SECRET_KEY
does not issue a warning because itβs simply null.DJANGO_ALLOWED_HOSTS
does because you try to split it. You have to pass those env vars to your container, either with the -e docker option or through an env file you create on spot.
So this definitely works:
...
Test stage:
stage: test
script:
...
- docker run --rm -e SECRET_KEY=mydummysecretkey_gitlab-ci -e DJANGO_ALLOWED_HOSTS='localhost 127.0.0.1 [::1]' $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA pytest
...
I ended up with something like this:
docker run --rm -e SECRET_KEY='$SECRET_KEY' -e DJANGO_ALLOWED_HOSTS='$DJANGO_ALLOWED_HOSTS' $CI_COMMIT_SHA pytest
π€Bravo2bad
Source:stackexchange.com