In documentation https://docs.gitlab.com/ci/variables/predefined_variables/ :
CI_COMMIT_TAG Pre-pipeline The commit tag name. Available only in pipelines for tags.
Also https://docs.gitlab.com/ci/yaml/#rulesif
So, it seems to me this should do what you want.
rules:
- if: $CI_COMMIT_TAG
when: never
- if: 'master' == $CI_COMMIT_BRANCH