Skip to content

Add !reference to the CI syntax to merge YAML arrays [RUN ALL RSPEC] [RUN AS-IF-FOSS]

Marius Bobin requested to merge ci-add-yaml-functors into master

What does this MR do?

Related to #266173 (closed)

Makes it possible to reference blocks of the CI definition across files:

# Content of setup.yml
.setup:
  script:
    - echo creating environment1 
    - echo creating environment2

# Content of teardown.yml
.teardown:
  script:
    - echo deleting environment1
    - echo deleting environment2

# .gitlab-ci.yml
include:
  - local: setup.yml
  - local: teardown.yml
 
test:
  script:
    - !reference [.setup, script]
    - echo running my own command
    - !reference [.teardown, script]

Variables example:

.vars:
  variables:
    URL: "http://my-url.internal"
    IMPORTANT_VAR: "the details"

# brings all variables from .vars
test vars 1:
  variables: !reference [.vars, variables]
  script:
    - printenv

# brings only IMPORTANT_VAR from .vars and exposes it as MY_VAR
test vars 2:
  variables: 
    MY_VAR: !reference [.vars, variables, IMPORTANT_VAR]
  script:
    - printenv

Screenshots (strongly suggested)

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team
Edited by Marius Bobin

Merge request reports

Loading