title: Difference between different GitLab CI Merge Request rules
body: <p>As several other users, I'm facing issues with <a href="https://docs.gitlab.com/ee/ci/jobs/job_control.html#avoid-duplicate-pipelines" rel="nofollow noreferrer">duplicate pipelines in GitLab CI/CD</a>. While there is some documentation on how to prevent this scattered around in the GitLab docs,
  my impression is that the indivdual docs pages and sections are rather inconsistent.</p>
  <p>My question is, what are the differences between the following rules? Or, more specifically, are there cases in which these rules are evaluated differently?</p>
  <ul>
  <li><p><a href="https://docs.gitlab.com/ee/ci/yaml/workflow.html#switch-between-branch-pipelines-and-merge-request-pipelines" rel="nofollow noreferrer">Switch between branch pipelines and merge request pipelines</a> suggest this to identify merge request pipelines:</p>
  <pre class="lang-yaml prettyprint-override"><code>if: '$CI_PIPELINE_SOURCE == &quot;merge_request_event&quot;'
  </code></pre>
  </li>
  <li><p>Additionally, <a href="https://docs.gitlab.com/ee/ci/yaml/workflow.html#switch-between-branch-pipelines-and-merge-request-pipelines" rel="nofollow noreferrer">Switch between branch pipelines and merge request pipelines</a> also uses this rule in combination with <code>$CI_COMMIT_BRANCH &amp;&amp;</code>:</p>
  <pre class="lang-yaml prettyprint-override"><code>if: '$CI_OPEN_MERGE_REQUESTS'
  </code></pre>
  </li>
  <li><p>Moreover, the <a href="https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Workflows/MergeRequest-Pipelines.gitlab-ci.yml" rel="nofollow noreferrer">MergeRequest-Pipelines.gitlab-ci.yml</a> uses a third rule:</p>
  <pre class="lang-yaml prettyprint-override"><code>if: $CI_MERGE_REQUEST_IID
  </code></pre>
  </li>
  </ul>
  <p>Any explanation or hints to docs pages I might have overlooked is highly appreciated.</p>