Run production builds on master branch only with tags

For production builds, I have the following code in .gitlab-ci.yaml:

production:
stage: deploy
script:
- pip install python-semantic-release # For auto semantic versioning when doing production release.
- mkdir -p $DEPLOY_DIR/$CI_ENVIRONMENT_NAME
- python setup.py bdist_wheel -d $DEPLOY_DIR/$CI_ENVIRONMENT_NAME
- python setup.py changelog --released > $DEPLOY_DIR/$CI_ENVIRONMENT_NAME/CHANGELOG.$(python setup.py --version).txt
environment:
name: production
only:
- tags

However, this also runs production build if I create a tag on the branch. How do I tell Gitlab to only run this workflow on tags when they are pushed/available on master branch? Should I be doing this?

only:

  • tags
    except:
  • branches