Conditional includes with exists are now supported with GitLab 14.5. Related issue: Support conditional includes with exists (#341511) · Issues · GitLab.org / GitLab · GitLab I’ve tried them in this project [image] Developer Evangelism at GitLab / playground / Conditional Includes with E… Answer from dnsmichi on forum.gitlab.com
🌐
GitLab
docs.gitlab.com › gitlab docs › use gitlab › use ci/cd to build your application › ci/cd yaml syntax reference
CI/CD YAML syntax reference | GitLab Docs
Use include to include external YAML files in your CI/CD configuration. You can split one long .gitlab-ci.yml file into multiple files to increase readability, or reduce duplication of the same configuration in multiple places.
🌐
GitLab
docs.gitlab.com › gitlab docs › use gitlab › use ci/cd to build your application › ci/cd yaml syntax reference › include examples
Use CI/CD configuration from other files | GitLab Docs
You can use include to include external YAML files in your CI/CD jobs. To include a single configuration file, use include by itself with a single file with either of these syntax options: ... If the file is a local file, the behavior is the same as include:local.
Discussions

Use of include in pipelines
have a nice day, everyone. I found such a thing that the linter, when using the include, skips and does not warn if you have a different job name and stage tag in the called file. For example, you have jobs A, B, C. In a job named A and stage name A1, you want to include some code, and mark ... More on forum.gitlab.com
🌐 forum.gitlab.com
9
0
December 23, 2022
GitLab-ci.yml include only includes the first job from the included file
GitLab-ci.yml include only includes the first job from the included file I’m currently setting up GitLab CI/CD in our repository since it’s been broken from the start, and I want to split up the YML files across multiple files. This is however causing problems With a filestructure like ... More on forum.gitlab.com
🌐 forum.gitlab.com
4
0
October 7, 2021
CI/CD: any substantial difference between component and project include?
There are a few benefits, mainly in terms of documentation and discoverability. A CI/CD component project is discoverable through the instance's CI/CD Catalog (gitlab.com/explore/catalog). With templates, you'll have to have your own internal documentation for how to find them. The component project has a special view that auto documents the spec:inputs of each component in the project. They're coupled to GitLab Releases in some interesting ways. Creating a release with a semantic version is required for the component to be populated in the instance's CI/CD Catalog, but it also allows consumers of the component to use semver ranges. So you might have components with 1.0.0, 1.0.1, and 1.0.2 releases, but your consumers can just include my-component:1 if they're tolerant to change. So yeah, for now most of the benefits are around how easy it is to discover and use components, and less around actually writing the components themselves, but that could always change in the future. It might not be worth refactoring all of your existing templates, but it's probably worth considering writing any new things as Components. More on reddit.com
🌐 r/gitlab
14
6
January 29, 2025
Include .gitlab-ci.yml multiple times with different configuration each time - Stack Overflow
We have a GitLab CI/CD .gitlab-ci.yaml file that builds software packages. This .gitlab-ci.yaml has a variable that determines which operating system release the package should be built for. We would More on stackoverflow.com
🌐 stackoverflow.com
🌐
GitLab
forum.gitlab.com › gitlab ci/cd
.gitlab-ci.yaml Conditional Includes - GitLab CI/CD - GitLab Forum
April 7, 2020 - I’d like to conditionally include a file based on some criteria. I’m creating a shared pipeline definition and I’d like to define things and run things only if the project the pipeline it’s running is has specific variables set or if a file exists in the directory.
🌐
Hifis
hifis.net › workshop-materials › gitlab-ci › episodes › 08-using-includes
Using Includes - Continuous Integration in GitLab
As demonstrated above, the simplest way to include YAML files in another one is to put the file to include somewhere in the same project and reference it with the include:local sub-key in the main YAML file .gitlab-ci.yml by using the relative path from the project root to the YAML file to include.
🌐
Medium
medium.com › @dhilipsingh92 › gitlab-ci-include-template-cf70b0705901
GitLab CI- Include & Template. What is GitLab Include? | by Dhilipsingh G | Medium
May 13, 2025 - The template keyword allows you to include official GitLab-managed CI/CD templates into your pipeline.
🌐
GitLab
forum.gitlab.com › gitlab ci/cd
Use of include in pipelines - GitLab CI/CD - GitLab Forum
December 23, 2022 - have a nice day, everyone. I found such a thing that the linter, when using the include, skips and does not warn if you have a different job name and stage tag in the called file. For example, you have jobs A, B, C. In a job named A and stage name A1, you want to include some code, and mark it in the included file, for example, job B, but leave stage A1, the included file will work in job B and linter is silent.
Find elsewhere
🌐
GitLab
forum.gitlab.com › gitlab ci/cd
GitLab-ci.yml include only includes the first job from the included file - GitLab CI/CD - GitLab Forum
October 7, 2021 - GitLab-ci.yml include only includes the first job from the included file I’m currently setting up GitLab CI/CD in our repository since it’s been broken from the start, and I want to split up the YML files across multiple files. This is however causing problems With a filestructure like this: Root ci/ build.gitlab-ci.yml gitlab-ci.yml Contents of gitlab-ci.yml: stages: - build - test - deploy include: - local: ci/build.gitlab-ci.yml Contents of build.gitlab-ci.yml: build: ...
🌐
Medium
ajanerom.medium.com › the-include-keyword-in-gitlab-pipelines-and-how-it-helped-me-bd167159cfdf
The include keyword in GitLab pipelines and how it helped me. | by Alexis Janero Moliner | Medium
March 26, 2021 - Use the include keyword to include external YAML files in your CI/CD configuration. You can break down one long gitlab-ci.yml file into multiple files to increase readability, or reduce duplication of the same configuration in multiple places.
🌐
GitLab
about.gitlab.com › blog › product › how to include file references in your ci/cd components
How to include file references in your CI/CD components
October 16, 2024 - CI/CD components are reusable units of pipeline configurations that get included in a pipeline when it’s created. The components bring additional jobs into the pipeline, however they can’t bring additional files as such reusable scripts. CI/CD Steps are reusable units of a job. Each step defines structured inputs and outputs that can be consumed by other steps. Steps can come from local files, GitLab.com repositories, or any other Git source.
🌐
GitLab
docs.gitlab.com › gitlab docs › use gitlab › use ci/cd to build your application › ci/cd components
CI/CD components | GitLab Docs
Test changes in a CI/CD pipeline (like any other project) by creating a .gitlab-ci.yml in the root directory. Make sure to test both the behavior and potential side-effects of the component. You can use the GitLab API if needed. ... include: # include the component located in the current project from the current SHA - component: $CI_SERVER_FQDN/$CI_PROJECT_PATH/my-component@$CI_COMMIT_SHA inputs: stage: build stages: [build, test, release] # Check if `component job of my-component` is added.
🌐
OneUptime
oneuptime.com › home › blog › how to use include templates in gitlab ci
How to Use Include Templates in GitLab CI
January 26, 2026 - When you need to update a security scan or deployment process, you end up editing dozens of files. GitLab CI's include feature lets you extract common configurations into reusable templates.
🌐
Baeldung
baeldung.com › home › devops › sharing gitlab ci/cd configurations across multiple projects
Sharing GitLab CI/CD Configurations Across Multiple Projects | Baeldung on Ops
August 25, 2024 - As expected, the hello_world job from the ci-common project was executed as part of the downstream pipeline. Parent-child pipelines are another interesting downstream pipeline scenario that allows us to share YAML files from one project into another. Contrary to the multi-project pipeline, such pipelines execute within the project that triggers them. Further, we must use the include and trigger keywords to write the parent-child pipeline within .gitlab-ci.yml under the proj-include-static-yaml project:
🌐
Reddit
reddit.com › r/gitlab › ci/cd: any substantial difference between component and project include?
r/gitlab on Reddit: CI/CD: any substantial difference between component and project include?
January 29, 2025 -

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 include methods support inputs specs

  • both methods support ref points (commit SHA, tag etc.)

Is there any added benefit of migrating an existing template to a CI/CD component?

🌐
GitLab
gitlab.com › gitlab.org › #219065
Variable can be used on `include.ref` in `.gitlab-ci.yml` (#219065) · Issues · GitLab.org / GitLab · GitLab
May 25, 2020 - I would like pipelines to reference the template from a tag: ```yaml include: project: 'my-group/ci-pipelines' ref: v1 file: 'templates/main.yml' ``` Then, if I create a new tag to fix a bug in the pipeline, I have to go through every single projects to update that ref to v2 which is long and cumbersome. ### Proposal If the `.gitlab-ci.yml` was allowing to reference a variable: ```yaml include: project: 'my-group/ci-pipelines' ref: $PIPELINE_TEMPLATE_REF file: 'templates/main.yml' ``` Then I would only have to update this variable in the group CI variables.
Top answer
1 of 4
5

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

2 of 4
4

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
🌐
GitLab
forum.gitlab.com › gitlab ci/cd
Gitlab-ci includes a file from another project that executes a script file - GitLab CI/CD - GitLab Forum
September 17, 2024 - I have two different projects. project1 and project2. Inside project1, I have file_project1 file: apply: stage: apply script: - bash folder/scripts/automation.sh rules: - if: $CI_PIPELINE_SOURCE == "push" when: always In project2, I have created the .gitlab-ci.yml and I have included the project1 and the file_project1: include: - project: 'namespace/project1' ref: main file: 'file_project1' During the execution, project2 does not recognize the folder/scripts/aut...
🌐
Spacelift
spacelift.io › blog › gitlab-ci-yml
Writing .gitlab-ci.yml File with Examples [Tutorial]
September 15, 2025 - Build outputs, test results, and compliance reports are some common types of artifacts, but there are no limitations on what you can include. In .gitlab-ci.yml, artifacts are specified using the artifacts keyword.
🌐
GitLab
docs.gitlab.com › gitlab docs › use gitlab › use ci/cd to build your application › ci/cd yaml syntax reference › optimize your yaml files
Optimize GitLab CI/CD configuration files | GitLab Docs
In the following example, a script is defined in the included.yml file. Then, in the .gitlab-ci.yml file, extends refers to the contents of the script:
🌐
Stack Exchange
devops.stackexchange.com › questions › 18152 › why-i-cant-include-a-yml-in-ci-cd-using-rules-with-mine-variables
gitlab - Why I can't include a .yml in CI/CD, using rules with mine variables? - DevOps Stack Exchange
include: - project: 'pipelines/cicd' ref: improve/simplificando-pipes file: 'libraries/bundle/java/maven/.gitlab-ci-native.template.yml' rules: - if $CI_COMMIT_MESSAGE =~ /.*--native-compile*/