Skip to content

gitlab-ci.yaml syntax for merging YAML arrays (i.e., script or after_script, rules, etc.)

Update

A solution for this issue was implemented in #266173 (closed) please review it first before adding your comment to this issue

Problem to solve

It is not possible to use multiple anchors to construct scripts or after_scripts, or any array in YAML. This would come in very handy in constructing more complex scripts without code duplication.

Intended users

User experience goal

Proposal

Support defining explicit merge behaviors within the script, before_script, and after_script sections as follows:

.setup:
  script: &setup_script
    - echo creating my environment 
    ...

.teardown:
  script: &teardown_script
    - echo deleting my environment
    ...

test:
  script: !merge
    - *setup_script
    - echo running my own command
    - *teardown_script

Or, for rules:

test:
  rules: !merge
    - *other-rule-1
    - *other-rule-2
    - *other-rule-3

Further details

Permissions and Security

Documentation

Availability & Testing

What does success look like, and how can we measure that?

What is the type of buyer?

Is this a cross-stage feature?

Links / references

Edited by Dov Hershkovitch