title: Gitlab-CI rules If/Changes do not work as expected
body: <p>We are working with Gitlab-CI and a strange behaviour just happened. We are trying to only run a given job (e.g, <code>lint</code> here below) only and only if we are in a merge request not a simple git branch, as well as only if <code>*.py</code> files shows changes. However, from what we have seen on the documentation we seems to be okay but not really as it do not work well at the moment. If, for example, I am going to push a change on the <code>Readme.MD</code>, the pipeline's job <code>Lint</code> here will be executed where it should have not.</p>
  <p>Please, if you have any ideas/tips, We would be very grateful.</p>
  <p>Thank you very much for your understanding,
  Bw.</p>
  <p>---&gt; Gitlab CI Yaml configuration:</p>
  <p>.gitlab-ci.yml:</p>
  <pre class="lang-yaml prettyprint-override"><code>image: python:3.7
  
  stages:
    - pre-build
    - test
  
  .ci_rules:
    rules:
      - if: '$CI_PIPELINE_SOURCE == &quot;merge_request_event&quot; &amp;&amp; $CI_MERGE_REQUEST_IID'
        changes:
          - tests/*.py
          - tests/*/*.py
          - src/*.py
          - src/*/*.py
      - if: $CI_COMMIT_REF_NAME == &quot;develop&quot;
      - if: $CI_COMMIT_REF_NAME == &quot;main&quot;
  
  lint:
    stage: pre-build
    script:
      - pip install flake8
      - flake8
    rules:
      - !reference [ .ci_rules, rules ]
  
  # [... other jobs not relevant for the issue]
  </code></pre>