Templates


Make jobs reusable

Job templates begin with a dot to prevent execution

Templates can be imported using include from…

See also the development guide for templates


Hands-On: Template and include

  1. Create inline tmplate:

     .build-go:
       script:
       - |
         go build \
             -ldflags "-X main.Version=${CI_COMMIT_REF_NAME} -X 'main.Author=${AUTHOR}'" \
             -o hello \
             .
    
  2. Use in build job

     build:
       extends: .build-go
       # ...
    
  3. Check pipeline


Hands-On: Local

  1. Add go.yaml to root of project
  2. Include go.yaml:

     include:
     - local: go.yaml
    
     build:
       extends: .build-go
       # ...
    
  3. Check pipeline

Hands-On: File

  1. Remove go.yaml from project
  2. Create a new project, e.g. template-go
  3. Add go.yaml to the root of the new project
  4. Include go.yaml:

     include:
     - project: <GROUP>/template-go
       ref: main
       file: go.yaml
    
  5. Check pipeline