Unexpected behaviour when doing a build without postgres keyword

Hello there everyone!

A few days ago, a developer came to me and said our in house gitlab-ci docker runner, would not work unless you include variables in the gitlab-ci.yml for postgres.

So a bit of information here, we primarily use an in house gitlab instance, inside the config.toml file for the docker ci container there is a service showen as below:-

[[runners.docker.services]]
  name = "postgres"
  alias = "postgres"

When I first set this up, it was under the assumption it was going to be used purely for ruby on rails builds but a dev has thrown a curve ball at me because hes trying to do a run that does not require a database, so he didn’t include the variables in the gitlab-ci.yml file for postgres, example of what would normally be there:-

services:
  - postgres

variables:
  POSTGRES_DB: 
  POSTGRES_USER: 
  POSTGRES_PASSWORD: "
  DB_HOST: 
  DB_NAME: 
  DB_USER: 
  DB_PASS:

We expected that if the yml file did not include the postgres keyword, under services, then gitlab would not start the postgres container when it tries to build, turns out this was wrong. It still starts postgres and it breaks because it needs variables.

So my question is, how can I configure it so gitlab will start a postgres container when we need it, but it wont if we dont need one?

All I can think of right now is I will need a separate runner, purely for builds that dont need a database, but I would prefer a one container that does all.

For the time being, the rest of the developers are just including them anyway, but it makes the yml file messy if they are not required.