Skip to content

Overriding variables in child pipeline jobs is inconsistent with regular pipeline jobs

Solution

Documented in #357275 (comment 1041613273)

Summary

When declaring a global variable, overriding it in a job template and running the same job in a parent pipeline and child pipeline, the variable overriding behavior differs between parent and child jobs (overridden in parent, not overridden in child).

Steps to reproduce

You need:

  • a global variable
  • pipeline job overriding and printing the variable
  • child pipeline with the exact same job
  • pipeline job triggering the child pipeline
.gitlab-ci.yml
stages:
  - one

include: /job.yml

variables:
  IMAGE: "A"

test_job:
  stage: one
  variables:
    IMAGE: "B"
  image: alpine
  extends:
    - .job

trigger_child:
  stage: one
  trigger:
    include: /child.yml
child.yml
stages:
  - one

include: /job.yml

test_job:
  stage: one
  variables:
    IMAGE: "B"
  image: alpine
  extends:
    - .job
job.yml
.job:
  script:
    - echo "IMAGE=$IMAGE"
  1. Run the pipeline
  2. See different outputs in the job run in the parent pipeline and the job run in the child pipeline

Example Project

I've created an example project where this can be observed.

What is the current bug behavior?

The test_job in the parent pipeline prints IMAGE=B as expected, while the test_job in the child pipeline prints IMAGE=A.

What is the expected correct behavior?

Expected behavior would be both jobs overriding the global variable (or it not being present at all in the child pipeline) and thus both printing IMAGE=B consistently.

Results of GitLab environment info

Tested on gitlab.com

Edited by Dov Hershkovitch