Templates contain required keywords
Templates must not be well-formed jobs
Job templates begin with a dot to prevent execution
Templates can be located in the same .gitlab-ci.yml
(inline)
Templates can be imported using include
from…
See also the official development guide for templates
The following pipeline…
.template:
image: alpine
script: pwd
job_name:
extends: .template
…result in the following job:
job_name:
image: alpine
script: pwd
Keywords from job_name
are applied after keywords from .template
The following pipeline…
.template:
image: alpine
script: pwd
job_name:
extends: .template
script: ls -l
…result in the following job:
job_name:
image: alpine
script: ls -l
Keywords from job_name
are applied after keywords from .template
The following pipeline…
.template:
image: alpine
variables:
foo: bar
script: pwd
job_name:
extends: .template
variables:
bar: baz
…result in the following job:
job_name:
image: alpine
variables:
foo: bar
bar: baz
script: pwd
Variables are merged!
See chapter Templates
Jobs can inherit from multiple templates
job_name:
extends:
- .template1
- .template2
With conflicting templates…
.template1:
script: pwd
.template2:
script: whoami
…last writer wins!
job_name:
script: whoami
But variables
are merged!
Conflicting templates…
.template1:
script: pwd
.template2:
script: whoami
…can be resolved by using reference tags
job_name:
script:
- !reference[.template1, script]
- !reference[.template2, script]