Use of include in pipelines
GitLab-ci.yml include only includes the first job from the included file
CI/CD: any substantial difference between component and project include?
Include .gitlab-ci.yml multiple times with different configuration each time - Stack Overflow
Hi Reddit!
I'm busy optimising CI configuration for our projects hosted in private Gitlab repositories.
I'm at a point where I extracted reusable and configurable jobs into a template. The template sits in a "toolbox" repository, and engineers can reuse it via include:project.
However, next to the include:project, we have include:component employing CI/CD components.
Given that:
-
the "toolbox" and other repositories are private
-
both
includemethods supportinputsspecs -
both methods support
refpoints (commit SHA, tag etc.)
Is there any added benefit of migrating an existing template to a CI/CD component?
You can include the same file multiple times, with different inputs. However, if multiple jobs with the same name are added to one pipeline, each additional job overwrites the previous job with the same name. You must ensure the configuration prevents duplicate job names.
For example, including the same configuration multiple times with different inputs:
include:
- local: path/to/my-super-linter.yml
inputs:
type: docs
lint-path: "doc/"
- local: path/to/my-super-linter.yml
inputs:
type: yaml
lint-path: "data/yaml/"
The configuration in path/to/my-super-linter.yml ensures the job has a unique name each time it is included:
spec:
inputs:
type:
lint-path:
---
"run-$[[ inputs.type ]]-lint":
script: ./lint --$[[ inputs.type ]] --path=$[[ inputs.lint-path ]]
Check Define inputs for configuration added with include
Maybe you can use extends ?
# common/gitlab-templates/.gitlab-ci.yaml
variables:
OS_RELEASE: change_me
.build-package:
script: echo "building for $OS_RELEASE"
In another GitLab project we would like to do something like this:
# Build for version 8.0
include:
- project: 'common/gitlab-templates'
file: '.gitlab-ci.yml'
build-package:
extends: .build-package
variables:
OS_RELEASE: 8.0
# Build for version 9.0
include:
- project: 'common/gitlab-templates'
file: '.gitlab-ci.yml'
build-package:
extends: .build-package
variables:
OS_RELEASE: 9.0
# Build for version 10.0
include:
- project: 'common/gitlab-templates'
file: '.gitlab-ci.yml'
build-package:
extends: .build-package
variables:
OS_RELEASE: 10.0