Conditional Builds, Stages and Jobs

Conditional Builds, Stages and Jobs

Sometimes you need to filter out and reject builds, stages and jobs by specifying conditions in your build configuration (your .travis.yml file). With conditionals, you can do that and more, let’s explore the full functionalities of Conditional Builds.


You can configure Travis CI to only run builds when certain conditions/criterium are met. Any builds that do not meet these conditions are listed in the Requests tab of your repository, even though the actual build is not generated. For example, this allows builds only to run on the master branch:

if: branch = master

Build requests that do not match the condition will not generate a build, but will be listed on the Requests tab.


You can set criterium in which that include stages when certain conditions are met. Stages that do not match the given condition are silently skipped. For example, this allows the deploy stage to run only on the master branch:

  - name: deploy
    # require the branch name to be master (note for PRs this is the base branch name)
    if: branch = master

Stages that do not match the condition will be skipped silently, or you can be notified if they fail.

Conditionally Allowing Jobs to Fail

You can allow jobs to fail only when certain conditions are met. For example, this will allow the job with the env var TWO=two to fail when the build runs on the branch dev:

  - ONE=one
  - TWO=two
    - if: branch = dev
      env: TWO=two


Conditional Builds is a great is a great way to really be strict with your builds and make sure it meets certain criterium before a build is triggered, and/or silently skipped over.

As always, you can email me at if you have any questions, or problems about Conditional Builds, or just want something answered about Conditional Builds in general.

Happy Building!