Job environment variables don't pass to postgres image

Hi folks. I’m trying to set up my postgres container with some variables declared at job level, but it breaks!

My master branch works with variables duplicated at job and at container level: https://github.com/dvasdekis/circleci-2.0-pytest-postgresql/blob/master/.circleci/config.yml

But if I consolidate the variables to only declaring them at job level, the Postgres image doesn’t accept them! https://github.com/dvasdekis/circleci-2.0-pytest-postgresql/blob/break_circleci/.circleci/config.yml

Thanks!

Hi there,

Welcome to the community!

You need to duplicate these because the job level env vars are not automatically passed into service containers.

Is there a way I can define the value once in the config file and pass them to all my other instances? So define the values once at the job level, and then in the container section of the yml I reference the job vars?

Sadly no because the config doesn’t support any sort of variable interpolation. You can simplify the env var a bit by using a connection URI with username, password, host, and database in a single line instead of using separate environment variables for each thing.

If your purpose here is merely to make things more DRY, I would expect YAML references to work here. Have a look at the Wikipedia page for YAML - it is rather good.