Unable to create different workflows for subfolders in a monorepo

Unable to create different workflows for subfolders in a monorepo

What are you seeing, and how does that differ from what you expect to see?

I want to create separate workflows in my monorepo to trigger different pipelines based on changes in specific subfolders. Specifically:

  • When changes are made in the service folder, I want the service pipeline to trigger.
  • When changes are made in the helm folder, I want the helm pipeline to trigger.
  • When both folders are changed in the same commit, both pipelines should trigger.

Currently, I am unable to configure this properly. Only one pipeline seems to trigger or both trigger unexpectedly, regardless of the folder where changes occur.

Steps to reproduce

Here is a simplified version of the configuration Iā€™m using in my .gitlab-ci.yml:

stages:
  - check_changes
  - test
  - work_flow

check_changes_service:
  stage: check_changes
  rules:
    - changes:
        - workflow/wf-2/**
      when: never
    - changes:
        - workflow/**
      when: always
  script:
    - echo "Changes detected in the workflow/service folder."
    - echo "Running the service build pipeline..."

check_workflow_changes_helm:
  stage: check_changes
  rules:
    - changes:
        - workflow/service/helm/**
      when: always
  script:
    - echo "Changes detected in the workflow/service/helm folder."
    - echo "Running the helm pipeline..."

The issue arises when changes are made in either the workflow/service folder or the workflow/service/helm folder, but the expected workflows do not trigger correctly. I have already attempted using different combinations of rules, changes, and when, but the behavior is inconsistent.

The goal is to trigger:

  • Service workflow when changes are made to the workflow/service folder.
  • Helm workflow when changes are made to the workflow/service/helm folder.
  • Both workflows when changes are made in both folders.

Versions

  • GitLab-com SaaS
  • Self-hosted Runners

Versions:

  • GitLab: GitLab SaaS (Latest version)
  • GitLab Runner: Shared GitLab Runners

I also have the same issue.

1 Like