How to run a gitlab child pipeline only on changes in merge requests?



  • According to the documentation, parent-child pipelines should work well with rules - so i'm trying to setup a parent-child pipeline, where the child pipelines only run when something has actually changed in the sub-service. Using the following setup:

    main .gitlab-ci.yml:

    trigger_service_a:
      trigger:
        include: service_a/.gitlab-ci.yml
      rules:
        - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
          changes:
            - service_a/*
          when: always
    

    service_a/.gitlab-ci.yml:

    
    workflow:
      rules:
        - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
          changes:
            - service_a/*
          when: always
    

    service_a:
    script:
    - echo "run"

    However, when i push in a merge request without changes inside service_a, the pipeline fails with : trigger_service_a - failed - (downstream pipeline can not be created, Pipeline filtered out by workflow rules.)

    Even if i change something in the service_a, i still get the same error.

    How can i trigger child-pipelines in branches and merge requests only when something has changed in the sub-service?



  • Why are you using the same rules for both parent and child pipelines? You are just triggering the child service if anything changes on files inside the child service directory So, just define rules on child pipeline... It will automatically trigger if any changes happen on service_a/*




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2