Answers: <p>Why are you using the same rules for both parent and child pipelines? You are just triggering the child service <code>if anything changes on files inside the child service directory</code>
  So, just define rules on child pipeline... It will automatically trigger if any changes happen on <code>service_a/*</code></p>
  
Answers: CC BY-SA 4.0
Answers: 2022-04-12T05:53:36.177Z
Answers: I tried to put this rule only in the child pipeline, but then i get the same error when service_a has no changes . if it has changes, it runs successfully.
Answers: pulse00
Answers: CC BY-SA 4.0
Answers: 2022-04-08T12:05:40.130Z
Answers: 2022-04-08T12:05:40.130Z
Answers: Sagar Budhathoki Magar
Body: <p>According to the documentation, parent-child pipelines should work well with <code>rules</code> - 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:</p>
  <p>main .gitlab-ci.yml:</p>
  <pre class="lang-yml prettyprint-override"><code>trigger_service_a:
    trigger:
      include: service_a/.gitlab-ci.yml
    rules:
      - if: '$CI_PIPELINE_SOURCE == &quot;merge_request_event&quot;'
        changes:
          - service_a/*
        when: always
  </code></pre>
  <p>service_a/.gitlab-ci.yml:</p>
  <pre class="lang-yml prettyprint-override"><code>
  workflow:
    rules:
      - if: '$CI_PIPELINE_SOURCE == &quot;merge_request_event&quot;'
        changes:
          - service_a/*
        when: always
  
  service_a:
    script:
      - echo &quot;run&quot;
  
  </code></pre>
  <p>However, when i push in a merge request without changes inside service_a, the pipeline fails with : <code>trigger_service_a - failed - (downstream pipeline can not be created, Pipeline filtered out by workflow rules.)</code></p>
  <p>Even if i change something in the service_a, i still get the same error.</p>
  <p>How can i trigger child-pipelines in branches and merge requests only when something has changed in the sub-service?</p>
  
Tags: <gitlab><gitlab-ci-runner>
Title: How to run a gitlab child pipeline only on changes in merge requests?
UserDisplayName: pulse00
ThreadText: # How to run a gitlab child pipeline only on changes in merge requests?
  
  (Asked by: username_0 on 2022-04-07)
  
  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:
  
  ```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:
  
  ```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?
  
  **Tags:** gitlab, gitlab-ci-runner
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2022-04-08. Score: 0
  
  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/*`
  
  > **Comments:**
  > **username_0**: I tried to put this rule only in the child pipeline, but then i get the same error when service_a has no changes . if it has changes, it runs successfully.  
  
  ---
  
  