Skip to content

Dotenv files

See also direnv.md how to auto-load .env files

Source .env from bash

Best solution so far (is able to ignores comments):

export $(grep -v '^#' .env | xargs)

Also handles values with spaces, but beware: -d is not supported in busybox (i.e. some Gitlab CI containers):

export $(grep -v '^#' .env | xargs -d '\n')

Source dotenv file in Gitlab CI

Add this command to the beginning of the job script:

script:
  - |
    [ -f .env ] && export $(grep -v '^#' .env | xargs)

Python