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
Create inline tmplate:
.build-go:
script:
- |
go build \
-ldflags "-X main.Version=${CI_COMMIT_REF_NAME} -X 'main.Author=${AUTHOR}'" \
-o hello \
.
Use in build job
build:
extends: .build-go
#...
Check pipeline
(See inline/.gitlab-ci.yml
)
go.yaml
to root of projectInclude go.yaml
:
include:
- local: go.yaml
build:
extends: .build-go
#...
(See local/.gitlab-ci.yml
)
go.yaml
from projecttemplate-go
go.yaml
to the root of the new projectInclude go.yaml
:
include:
- project: <GROUP>/template-go
ref: main
file: go.yaml
(See file/.gitlab-ci.yml
)
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]