Run gitlab-ci.yml only when merge request to master made

Try

only:
  - master

origin is just a name for a remote. master is the name of the branch.

The runner is triggered by GitLab-CI the moment that a commit is pushed to the repository, so alas not upon merge request.

You can use a trigger to trigger a pipeline and then call that trigger from a merge request event in integrations.


Restrict stages to Merge Requests:

To have your test stage only being executed when a Merge Request (MR) is opened, use

   only:
     - merge_requests

According to the Gitlab docs, you can further restrict this to only being executed for MRs with a certain target branch, e.g. only MRs for master

   only:
     - merge_requests
   except:
     variables:
       - $CI_MERGE_REQUEST_TARGET_BRANCH_NAME != "master"

This adds an exception for all target branches that are not master.

Or use rules: for that:

  rules:
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master"'

Restrict stages to Branches:

As already mentioned by @marcolz, this is achieved by

   only:
     - master

to only execute the stage for pushes to the master branch.