Skip to content

Support Project variables in include: section of gitlab-ci.yml

Release notes

Problem to solve

Currently, variables cannot be used in the include section of the gitlab-ci.yml.

One of the requirement of group-level compliance pipeline configuration is to be able to use the predefined variable $CI_PROJECT_CONFIG_PATH in the include section. This will be used to make a callback the project pipeline from the group-level compliance pipeline.

This issue proposes the ability to expand pre-defined project variables while evaluating the include section.

Please note this issue addresses part of the issue to support a wider range of variables in the include section.

Intended users

Proposal

Expand the project variables in the External::Mapper class before the include section is evaluated.

Technical Implementation

Config::External::Context.new(
  ...
  variables: project&.predefined_variables
)
def initialize(project: nil, sha: nil, user: nil, parent_pipeline: nil, variables: [])
  ...
  @variables = variables
  ...
end
  • Update expand_context_attrs to include the variables context (project, file)
def expand_context_attrs
  {
     ...
     variables: context.variables
  }
end
  • Expand variables before include section is evaluated in the mapper:
ExpandVariables.expand(data, @context.variables)

Further details

#30686 (comment 448318651) suggests a rough implementation plan.

Feature flag

variables_in_include_section_ci - defaults to false

Links / references

Demo

include-section-variable-demo

Edited by Aishwarya Subramanian