Gitlab services aren't picking up variables set in .gitlab-ci.yml
Summary
Services are not picking up environment variables set for them in .gitlab-yi.yml
.
Steps to reproduce
Make a simple .gitlab-ci.yml like this:
stages:
- test
test_postgres_exists:
stage: test
services:
- name: bitnami/postgresql:15.3.0
alias: postgresql
variables:
POSTGRESQL_DATABASE: testdb
POSTGRESQL_USERNAME: testuser
POSTGRESQL_PASSWORD: testuser-fake-password
POSTGRESQL_POSTGRES_PASSWORD: postgres-fake-password
script:
- echo "scoll up and see how POSTGRESQL_PASSWORD is not set."
Then run the continuous integration. You will note that the postgresql service says that POSTGRESQL_PASSWORD is not set, even though that variable ought to be set.
Example Project
https://gitlab.com/skye.berghel/postgres-ci-test
What is the current bug behavior?
The variables set in the service's variables
configuration are not used.
What is the expected correct behavior?
The service can have variables configured in its variables
section.
Relevant logs and/or screenshots
Service container logs:
2023-11-16T01:11:55.168124814Z postgresql 01:11:55.16
2023-11-16T01:11:55.172402804Z postgresql 01:11:55.16 Welcome to the Bitnami postgresql container
2023-11-16T01:11:55.172445684Z postgresql 01:11:55.17 Subscribe to project updates by watching https://github.com/bitnami/containers
2023-11-16T01:11:55.178184812Z postgresql 01:11:55.17 Submit issues and feature requests at https://github.com/bitnami/containers/issues
2023-11-16T01:11:55.179447390Z postgresql 01:11:55.17
2023-11-16T01:11:55.192707828Z postgresql 01:11:55.19 INFO ==> ** Starting PostgreSQL setup **
2023-11-16T01:11:55.227810716Z postgresql 01:11:55.22 INFO ==> Validating settings in POSTGRESQL_* env vars..
2023-11-16T01:11:55.229333192Z postgresql 01:11:55.22 ERROR ==> The POSTGRESQL_PASSWORD environment variable is empty or not set. Set the environment variable ALLOW_EMPTY_PASSWORD=yes to allow the container to be started with blank passwords. This is recommended only for development.
2023-11-16T01:11:55.246024698Z postgresql 01:11:55.23 ERROR ==> The POSTGRESQL_PASSWORD environment variable is empty or not set. Set the environment variable ALLOW_EMPTY_PASSWORD=yes to allow the container to be started with blank passwords. This is recommended only for development.
Output of checks
This bug happens on GitLab.com
Potential Workaround
As noted by Louis Tung's comment in the related issue:
Same here, for those who needs a workaround, here is how I do it by passing the env variables directly to the shell and execute the program in docker.
services:
- name: postgres:13
command:
- env
- ENV1=...
- env
- ENV2=...
- /bin/bash
- {PATH_TO_EXECUTE_THE_APPLICATION_IN_DOCKER}
Edited by Alvin Gounder