'Trigger Gitlab CI workflow when changes to the file specified are pushed to master

I have following workflow rules defined:

workflow:
  rules:
    - if: '$CI_COMMIT_BRANCH == "master"'
      changes:
        - "**/test.txt"

To summarize I want this work follow to be triggered when both below conditions are met:

  1. There are changes to any of the file in repository with name test.txt
  2. The changes are pushed to master i.e. a merge request is approved.

However, this workflow never gets triggered, even after changes to test.txt are pushed to master or a branch containing those changes is merged.

What might be wrong here?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source