How do I use the include section in a pipeline as code?

Modified on Wed, 21 Jun 2023 at 02:18 PM

When working with GitLab pipelines as code, the include section allows you to include shared configuration files in your pipeline definition. This helps you avoid duplication and ensures consistency across multiple projects or pipelines. Here's how you can use the include section effectively:

Create a separate YAML configuration file that contains the shared configuration or stages you want to include in your pipeline. For example, let's say you have a file named shared.yml with the following content:

  - build
  - test

  stage: build
    - echo "Building the project..."

  stage: test
    - echo "Running tests..."

In your main pipeline configuration file (e.g., .gitlab-ci.yml), use the include section to reference the shared configuration file. Specify the file path relative to your repository.

  - local: '/path/to/shared.yml'

  - deploy

  stage: deploy
    - echo "Deploying the application..."

The include section allows you to bring in the stages and jobs defined in the shared configuration file (shared.yml in this example) into your main pipeline configuration.

With the include section, you can easily reuse and maintain shared configuration across multiple pipelines or projects. Any changes made to the shared configuration file will be automatically reflected in all the pipelines that include it.

By leveraging the include section in your pipeline as code, you can streamline your pipeline definitions, improve code reusability, and ensure consistency across your CI/CD workflows.

To further optimize your pipeline management and enhance your CI/CD processes, consider exploring Cloud-Runner provides high-performance GitLab runners and advanced features to help you maximize the efficiency and scalability of your pipelines. Visit to learn more and take your pipelines to the next level.

By utilizing the include section in your GitLab pipeline as code, you can simplify your configuration, reduce duplication, and maintain consistency across your projects and pipelines.

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select atleast one of the reasons

Feedback sent

We appreciate your effort and will try to fix the article