2

In Gitlab CI it is possible to include one or many files in a .gitlab-ci.yml file. It is even possible to nest these includes. See https://docs.gitlab.com/ee/ci/yaml/includes.html#using-nested-includes.

How can I see the resulting CI file all at once?

Right now, when I debug a CI cycle, I open every single include file and combine the resulting file structure by myself. There has to be a better way.

Example

Content of https://company.com/autodevops-template.yml:

variables:
  POSTGRES_USER: user
  POSTGRES_PASSWORD: testing_password
  POSTGRES_DB: $CI_ENVIRONMENT_SLUG

production:
  stage: production
  script:
    - install_dependencies
    - deploy
  environment:
    name: production
    url: https://$CI_PROJECT_PATH_SLUG.$KUBE_INGRESS_BASE_DOMAIN
  only:
    - master

Content of .gitlab-ci.yml:

include: 'https://company.com/autodevops-template.yml'

image: alpine:latest

variables:
  POSTGRES_USER: root
  POSTGRES_PASSWORD: secure_password

stages:
  - build
  - test
  - production

production:
  environment:
    url: https://example.com

This should result in the following file structure:

image: alpine:latest

variables:
  POSTGRES_USER: root
  POSTGRES_PASSWORD: secure_password
  POSTGRES_DB: $CI_ENVIRONMENT_SLUG

stages:
  - build
  - test
  - production

production:
  stage: production
  script:
    - install_dependencies
    - deploy
  environment:
    name: production
    url: https://example.com
  only:
    - master

→ How can I see this output somewhere?

Environment

  • Self-Hosted GitLab 13.9.1
pixelbrackets
  • 1,958
  • 19
  • 28

2 Answers2

0

As I continued to search for a solution, I read about a “Pipeline Editor“ which was released in GitLab version 13.8 this year. Turns out that the feature I am looking for was added to this editor just some days ago:

Version 13.9.0 (2021-02-22) „View an expanded version of the CI/CD configuration” → see Release Notes for a feature description and introduction video.

To view the fully expanded CI/CD configuration as one combined file, go to the pipeline editor’s »View merged YAML« tab. This tab displays an expanded configuration where:

  • Configuration imported with include is copied into the view.
  • Jobs that use extends display with the extended configuration merged into the job.
  • YAML anchors are replaced with the linked configuration

Usage: Open project → Module »CI / CD« → Submodule »Editor« → Tab »View merged YAML«

Screenshot Pipeline Editor Merged Configuration Tab

pixelbrackets
  • 1,958
  • 19
  • 28
0

GitLab 15.1 offers an altervative:

Link to included CI/CD configuration from the pipeline editor

A typical CI/CD configuration uses the include keyword to import configuration stored in other files or CI/CD templates. When editing or troubleshooting your configuration though, it can be difficult to understand how all the configuration works together because the included configuration is not visible in your .gitlab-ci-yml, you only see the include entry.

In this release, we added links to all included configuration files and templates to the pipeline editor.

Now you can easily access and view all the CI/CD configuration your pipeline uses, making it much easier to manage large and complex pipelines.

https://www.youtube.com/watch?v=7BNDUYfY_ok

See Documentation and Issue.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250