CI only happens when you make merge request to master branch

Hello everyone,
I am trying to set up my .yml file so that the CI only happens after aa merge request to the master branch and not on each merge request. I am wondering what line(s) I can aadd to my .yml file in order to complete this action. Thank you!

Check Pipelines for merge requests | GitLab

You can add the line

  only:
    - master

To your pipeline.

stages:
  - build
  
  #- test

only:
  - master

So I would add it like this if I am only running the build?

stages:
  - build
  
  #- test

 
build:
  stage: build
  script: ./build
  only:
    - master

I have done that, like the link says but I m getting back an error of jobs:build config key may not be used with rules: only What am I doing wrong here?