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]string field to jsonService with omitempty
  • Populate Variables from Image.Variables in getCIJobServicesEnv()
  • Add 3 new test cases: single variable, multiple variables, mixed services (with and without variables)
  • Fix strings.Split to strings.SplitN(n=2) in test helpers to correctly handle variable values containing =
  • Update docs/executors/custom.md to document the new variables field, 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?

  1. Configure a custom executor with a prepare_exec script that prints $CUSTOM_ENV_CI_JOB_SERVICES
  2. Define a CI job with a service that includes variables:
services:
  - name: redis:latest
    variables:
      REDIS_PASSWORD: secret
  1. Verify the variables key appears in the JSON output of $CUSTOM_ENV_CI_JOB_SERVICES

Unit tests:

go test ./executors/custom/... -run TestExecutor_ServicesEnv -v

What are the relevant issue numbers?

Closes #39331 (closed)

Edited by Sepehr Heydari

Merge request reports

Loading