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))