Expose service variables in custom executor CUSTOM_ENV_CI_JOB_SERVICES
What does this MR do?
Expose service variables in the $CUSTOM_ENV_CI_JOB_SERVICES environment variable for custom executors.
The jsonService struct, which is serialized into $CUSTOM_ENV_CI_JOB_SERVICES, was missing a Variables field. Any variables defined on a CI service (e.g. POSTGRES_PASSWORD, REDIS_PASSWORD) were silently dropped and never available to custom executor scripts during the prepare stage.
Before:
[{"name":"redis:latest","alias":"redis-test","entrypoint":null,"command":null}]After:
[{"name":"redis:latest","alias":"redis-test","entrypoint":null,"command":null,"variables":{"TEST_VAR":"hello-from-service"}}]Changes:
- Add
Variables map[string]stringfield tojsonServicewithomitempty - Populate
VariablesfromImage.VariablesingetCIJobServicesEnv() - Add 3 new test cases: single variable, multiple variables, mixed services (with and without variables)
- Fix
strings.Splittostrings.SplitN(n=2)in test helpers to correctly handle variable values containing= - Update
docs/executors/custom.mdto document the newvariablesfield, including an updated example and a field reference table
Why was this MR needed?
Custom executor scripts receive service metadata via $CUSTOM_ENV_CI_JOB_SERVICES but had no way to access service-level variables. The only workaround was manually parsing the raw job response file.
Fixes #39331 (closed)
What's the best way to test this MR?
- Configure a custom executor with a
prepare_execscript that prints$CUSTOM_ENV_CI_JOB_SERVICES - Define a CI job with a service that includes variables:
services:
- name: redis:latest
variables:
REDIS_PASSWORD: secret- Verify the
variableskey appears in the JSON output of$CUSTOM_ENV_CI_JOB_SERVICES
Unit tests:
go test ./executors/custom/... -run TestExecutor_ServicesEnv -vWhat are the relevant issue numbers?
Closes #39331 (closed)
Edited by Sepehr Heydari