Skip to content

Inputs are overwritten when the same component is used twice with an extended job

Summary

When using the same component twice, if a job in this component extends another job then inputs will be overwritten by the last include.

Steps to reproduce

.gitlab-ci.yml

stages:
  - test

include:
  - component: $CI_SERVER_FQDN/user/project/component@main
    inputs:
      foo: A
  - component: $CI_SERVER_FQDN/user/project/component@main
    inputs:
      foo: B

templates/component.yml

spec:
  inputs:
    foo:
---
"job-$[[ inputs.foo ]]":
  stage: test
  variables:
    FOO: $[[ inputs.foo ]]
  script:
    - "echo Foo: $[[ inputs.foo ]] $FOO"

.extended:
  stage: test
  variables:
    FOO: $[[ inputs.foo ]]
  script:
    - "echo Foo: $[[ inputs.foo ]] $FOO"

"job-$[[ inputs.foo ]]-extended":
  extends: .extended

Example Project

https://gitlab.com/macier/gitlab-component-extend-bug

What is the current bug behavior?

job-A output

$ echo Foo: A $FOO
Foo: A A

job-A-extended output (BUG)

$ echo Foo: B $FOO
Foo: B B

job-B output

$ echo Foo: B $FOO
Foo: B B

job-B-extended output

$ echo Foo: B $FOO
Foo: B B

What is the expected correct behavior?

job-A-extended should output :

$ echo Foo: A $FOO
Foo: A A

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