Combine multiple jobs inside the .gitlab-ci.yml

I develop and publish Bicep IaC modules, which involve various jobs such as building, testing, publishing, and updating documentation. To manage these tasks efficiently, I have created multiple .yml files, each containing a specific job.

In the main .gitlab-ci.yml file, I need to define a single section that references all the jobs specified in the template files. For example, when creating a Storage Account module, I want to add a corresponding section in the .gitlab-ci.yml file that calls all relevant jobs from the template while passing the required input variables. Similarly, for another module, I would create a new block with different input variables.

I would like to know if it is possible to configure .yml files in this manner. If anyone has insights or suggestions, I would greatly appreciate your help.

Steps to reproduce

Code given below.

Configuration

build-bicep.yml

spec:
  inputs:
    templatePath:
    moduleName:
---
.Build-bicep-file:
  stage: build
  artifacts:
    paths:
      - Build
  script:
    - pwsh -Command '
      $Params = @{
      Task = "BuildBicep";
      TemplatePath = "$[[ inputs.templatePath ]]/$[[ inputs.moduleName ]]"
      };
      Invoke-Build @Params
      '

test-bicep.yml

spec:
  inputs:
    TemplateDirectory:
---
.Test-bicep-file:
  stage: test
  script:
    - pwsh -Command '
      $Params = @{
      Task = "TestBicep";
      TemplatePath = "$[[ inputs.TemplateDirectory ]]"
      };
      Invoke-Build @Params
      '

.gitlab-ci.yml

workflow:
  name: "Pipeline for branch: $CI_COMMIT_BRANCH"
  rules:
    - if: $CI_PIPELINE_SOURCE == 'merge_request_event' H
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
    - 
default:
  image: mcr.microsoft.com:powershell
stages:
  - build
  - test

include:
  - local: "templates/build-bicep.yml"
  - local: "templates/test-bicep.yml"
  - local: "templates/validate-bicep.yml"

Bake-StorageAccount:
  extends:
    - .Build-bicep-file:
    - .Test-bicep-file
   inputs:
     templatePath: "modules"
     moduleName: "storageaccount"
     TemplateDirectory: "Build"

Bake-keyVault
  extends:
    - .Build-bicep-file:
    - .Test-bicep-file
   inputs:
     templatePath: "modules"
     moduleName: "keyvault"
     TemplateDirectory: "Build"

Versions

Please select whether options apply, and add the version information.

  • Self-managed
  • [x ] GitLab.com SaaS
  • Dedicated
  • Self-hosted Runners