Skip to content
GitLab
Next
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • GitLab GitLab
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 44,761
    • Issues 44,761
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
    • Requirements
  • Merge requests 1,329
    • Merge requests 1,329
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Container Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Metrics
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • GitLab.orgGitLab.org
  • GitLabGitLab
  • Issues
  • #266173
You need to sign in or sign up before continuing.
Closed
Open
Issue created Oct 11, 2020 by Dov Hershkovitch@dhershkovitch🗒Developer

Merge YAML block from includes

This issue is a followup from #16376 (comment 423199984)

Release notes

Previously it was impossible to refer to sections of a yaml file to be used as a part of your pipeline, in this release we've allowed you to merge specific keys from multiple yaml file into a single pipeline configuration, this allows you to maintain a single location of pipeline actions (such as setups, teardowns, etc...) to be used and referred along side your jobs.

Problem to solve

We would like to merge content from another YAML file to support the following:

# 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] # or any other name that would allow us to "include in this context some other value"
    - echo running my own command
    - !reference [.teardown, script]

This will result in the following:

echo creating environment1 
echo creating environment2
echo running my own command
echo deleting environment1
echo deleting environment2

The example below will merge script however we need to make sure to support any other key that is under job such as rules

The following section in the documentation needs to get updated https://docs.gitlab.com/ee/ci/yaml/README.html#include

Edited Feb 28, 2021 by Dov Hershkovitch
Assignee
Assign to
Time tracking