Gitlab merge rule based on file path

Viewed 11

How to setup merge rule when diff contains changes from certain file paths, merge request will require approval and reviewer

Use case

  • k8s repo contains staging / dev / prod env yaml files
  • Any change to file containing /prod/ need mandatory reviewer.
 rules:
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
      changes:
        - /prod/*
1 Answers

Merge request (MR) approvals are not linked to the CI YAML rules. CI rules only control whether a CI job is run.

If you need to require approvals based on changes to specific files, GitLab covers this through the code owners feature. Note however that it's a paid feature.

I'm not sure there is a way to do what you want without any paid features, since required approvals is also a paid feature.

GitLab would not prevent the actual merge, but you could use something like the GitLab triage gem to comment on the merge request who should approve the merge request before it's merged. Similarly, you could use the CI rules to trigger a job that uses the Notes API to add a comment on the MR.

Related