Services pollute environment variables in CI/CD
Using a service creates global environment variables and it's causing problems during builds. For example, having something like this:
build:
stage: build
services:
- name: postgres:15
alias: postgres_host
- name: custom-postgres:15
alias: postgres
This will result in environment variables that are prefixed with the service name and/or the alias.
- It creates variables identical to ones used by the services and code internally, but with non-standard values. What caused issues for me was
POSTGRES_PORT
being created with a value oftcp://172.17.0.3:5432
. This misconfigures tests when they run. - There seems to be no way to disable this behavior.
- The only way to avoid is to use custom images and being careful with the aliases.
- It's not documented in environment nor service pages.