Variables from dotenv files not expanding in service container variables
Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.
Summary
We previously added service variables in this MR: gitlab-runner!3158 (closed)
In this MR, there was a test to check that variable expansion is working correctly: gitlab-runner!3158 (comment 829286124)
However, when using variables from dotenv artifacts in service container definitions (jobs.services.variables
), the variables are not being expanded properly.
Steps to reproduce
- Create a pipeline with the following configuration:
stages:
- prepare
- check
variables:
MY_SERVICE_GLOBALVAR: "from-global"
CI_DEBUG_SERVICES: "true"
prepare:
stage: prepare
script:
- echo 'MY_SERVICE_IMAGE=busybox:latest' >> service.env
- echo 'MY_SERVICE_DOTENVVAR=from-dotenv' >> service.env
artifacts:
reports:
dotenv: service.env
build:
stage: check
needs:
- job: prepare
artifacts: true
services:
- name: $MY_SERVICE_IMAGE
entrypoint: [ "sh", "-c", "echo $SERV_GLOBAL $SERV_DOTENV" ]
variables:
SERV_GLOBAL: "$MY_SERVICE_GLOBALVAR"
SERV_DOTENV: "$MY_SERVICE_DOTENVVAR"
script:
- echo "hello world!"
- Run the pipeline
- Check the service container logs in the
build
job
Example Project
What is the current bug behavior?
The service container logs only show the global variable expanded, while the dotenv variable is empty:
Service container logs:
2025-08-19T02:25:35.587804448Z from-global
What is the expected correct behavior?
The service container logs should show both variables expanded correctly:
Service container logs:
2025-08-19T02:25:35.587804448Z from-global from-dotenv
Relevant logs and/or screenshots
Output of checks
This bug happens on GitLab.com
Results of GitLab environment info
Expand for output related to GitLab environment info
(For installations with omnibus-gitlab package run and paste the output of: `sudo gitlab-rake gitlab:env:info`) (For installations from source run and paste the output of: `sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production`)
Results of GitLab application Check
Expand for output related to the GitLab application check
(For installations with omnibus-gitlab package run and paste the output of:
sudo gitlab-rake gitlab:check SANITIZE=true
)(For installations from source run and paste the output of:
sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production SANITIZE=true
)(we will only investigate if the tests are passing)
Possible fixes
Patch release information for backports
If the bug fix needs to be backported in a patch release to a version under the maintenance policy, please follow the steps on the patch release runbook for GitLab engineers.
Refer to the internal "Release Information" dashboard for information about the next patch release, including the targeted versions, expected release date, and current status.
High-severity bug remediation
To remediate high-severity issues requiring an internal release for single-tenant SaaS instances, refer to the internal release process for engineers.