continuous-integrationgitlabgitlab-cinested-includes

How to print/debug all jobs of includes in GitLab CI?


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


Solution

  • 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