Travis CI: Branch Filters in Build Matrix items

We are wondering whether there is any way to add filters to Travis matrix items. In our particular case, we wish to run certain jobs only on specific branches.

The following example would be an ideal way for configuring this scenario, however it doesn’t seem to work:

matrix:
  include:
    - env: BUILD_TYPE=release
      branches:
        only:
          - master
    - env: BUILD_TYPE=ci
      branches:
        only:
          - develop
          ```
As a workaround, we can exit from the build script immediately by checking the appropriate env vars (TRAVIS_BRANCH), but it is very far from ideal as launching the slave machine and cloning the repo takes a considerable amount of time.

Hey @OliBarrington,

Try taking a look at Conditional Build Stages. It would look something like this:

jobs:
  include:
    - stage: release
      if: branch = master
      env: BUILD_TYPE=release
    - stage: ci
      if: branch = develop
      env: BUILD_TYPE=ci

Hope this solves your issue!

-Montana (Travis CI Staff)

Grazie! You’re always a great help @Montana!

No problem Oli! Anytime you need help just come back, and I will do my best!

-Montana (Travis CI Staff)

Imprint