Only running tests on original gitlab server

I have in my .gitlab-ci.yml some test stages. When I push my project to another gitlab server, these stages will fail, because no suitable runners are attached.

Thus I would like to do something like this to prevent these tests from running on other gitlab servers.

.only_deif:
  rules:
    - if: '$CI_SERVER_HOST == "gitlab.deif.com"'

test_deif:
  extends: .only_deif
  script:
    - set

This however creates two pipelines, which I do not want.

I have tried with this

.only_deif:
  rules:
    - if: $CI_PIPELINE_SOURCE == "merge_request_event"
      when: never
    - if: '$CI_SERVER_HOST == "gitlab.deif.com"'

But then I will get a green pipeline on the merge request, even if it fails. :frowning:

This also behaves bad as it does not build before the MR is made, and does not build on merge to master.

workflow:
  rules:
    - if: '$CI_PIPELINE_SOURCE != "push"'

There must be somebody who have done this trick.

GitLab Community Edition 13.12.4

This is perhaps my best solution

# to prevent detached pipelines, do not run anything in push
workflow:
  rules:
    - if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS && $CI_PIPELINE_SOURCE == "push"
      when: never
    - when: always

# Only run specified jobs on gitlab.deif.com
.only_deif:
  rules:
    - if: '$CI_SERVER_HOST != "gitlab.deif.com"'
      when: never
    - when: always

It has the drawback, that if the job contains a “rules”, then I need to copy paste parts of .only_deif into that rule.