Only build tags that are on the master branch

In a tag build, branch is equal to the tag name so your current condition is false.

See Using `branches:` filter unexpectedly prevents tags from being built, too and Travis-ci.com pointlessly builds tags for why that is.

Use OR to build both master and tags:

if: branch = master OR tag IS present

If you want to additionally check if the tag is on the master branch, you need to do that by hand early in the build:

if [[ -n $TRAVIS_TAG ]]; then
  # Travis does a shallow clone by default
  # so `master` is not present in the local metadata
  # in a build for another branch
  git fetch origin master:master   
  if ! (git branch --contains "$TRAVIS_TAG" | grep -qxE '. master'); then
    travis_terminate 0    # quit the build early
  fi
fi
1 Like