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,758
    • Issues 44,758
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
    • Requirements
  • Merge requests 1,331
    • Merge requests 1,331
  • 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
  • #28987
Closed
Open
Issue created May 25, 2019 by Elan Ruusamäe@glensc🇪🇪Contributor

Can't extend CI YAML templates in a reusable and non-breaking way

Proposed workaround

based on the comment

As a workaround you can prefix the include with arbitrary number of slashes:

Job1.yaml

include:
  - /Template.yaml

Job2.yaml

include:
  - //JobTemplate.yaml

Job3.yaml

include:
  - ///JobTemplate.yaml

Issue description

I'm trying to write re-usable fragments with yaml in a non breaking manner (so that don't have to update downstream projects).

Something like:

# FILE: project/.gitlab-ci.yml
include:
  - https://example.org/phpunit.yml
  - https://example.org/stylecheck.yml

and wanting to add TEST_DISABLED support to each test stage job, I created base include:

# FILE: tests.yml
# adds fragment which all jobs in "test" stage should inherit
# tests can be disabled by setting TEST_DISABLED variable
# https://docs.gitlab.com/ce/topics/autodevops/#environment-variables

.ci:stage:test:
  stage: test
  only:
    refs:
      - branches
      - tags
  except:
    variables:
      - $TEST_DISABLED

# vim:ts=2:sw=2:et
# FILE: phpunit.yml
include:
  - https://example.org/tests.yml

variables:
  PHPUNIT_IMAGE: $CI_REGISTRY/phpunit:php-$PHP_VERSION

phpunit:
  extends: .ci:stage:test
  image: $PHPUNIT_IMAGE
  dependencies:
    - composer
  coverage: '/^\s*Lines\s*:\s*\d+\.?\d+\%/'
  script:
    - vendor/bin/phpunit

# vim:ts=2:sw=2:et
# FILE: stylecheck.yml
include:
  - https://example.org/tests.yml

php-cs-fixer:
  extends: .ci:stage:test
  image: $CI_REGISTRY/php-cs-fixer:php-5.6
  dependencies:
    - composer
  allow_failure: true
  script:
    - php-cs-fixer fix --verbose --diff --dry-run --ansi

# vim:ts=2:sw=2:et

but using this solution breaks the pipeline creation:

Include `{"remote":"https://example.org/tests.yml"}` was already included!

Technical Proposal

The proposal is to allow including duplicate yml file in the same configuration Per #28987 (comment 507146848) In addition, if we won't raise any warning (because of #28987 (comment 528855946)) this is not a breaking changes

Documentation

We should provide some examples on our documentation on how we override the same configuration with the latest include (e.g. #28987 (comment 514209638))

Edited Dec 09, 2021 by Dov Hershkovitch
Assignee
Assign to
Time tracking