Conditional Deployments

This page documents deployments using the next major version dpl v2 which currently is in a beta release phase. Please see our blog post for details. The current default version is dpl v1. Check dpl v1 documentation here.

Set your build to deploy only in specific circumstances by using the on option for any deployment provider.

deploy:
  provider: <provider>
  # ⋮
  on:
    branch: release
    condition: $MY_ENV = value

If all conditions specified in the on section are met, your build will deploy.

The following conditions are available:

Repo #

To deploy only when the build occurs on a particular repository, add repo in the form owner_name/repo_name:

deploy:
  provider: <provider>
  # ⋮
  on:
    repo: travis-ci/dpl

Branch #

By default, deployments will only happen on the master branch. You can overwrite this by using the branch and all_branches options.

For example, to deploy on the production branch only use:

deploy:
  provider: <provider>
  # ⋮
  on:
    branch: production

In order to deploy from all branches:

deploy:
  provider: <provider>
  # ⋮
  on:
    all_branch: true

Condition #

You can specify a single Bash condition that needs to evaluate to true in order for the deployment to happen.

This must be a string value that will be wrapped into if [[ <condition> ]]; then <deploy>; fi.

For example, in order to only deploy if $CC is gcc use:

deploy:
  provider: s3
  # ⋮
  on:
    condition: $CC = gcc

Tag #

You can specify whether or not to deploy on tag builds using the option tags. If set to to true the deployment will only happen on tag builds, if set to false it will not happen on tag builds.

For example, in order to deploy on tag builds only:

deploy:
  provider: <provider>
  # ⋮
  on:
    tags: true
  • tags can be true, false or any other string:

This will check if the environment variable $TRAVIS_TAG is set. Depending on your workflow, you may set $TRAVIS_TAG explicitly, even if this is a non-tag build when it was initiated.

Setting tags to true causes the branch condition to be ignored, otherwise $TRAVIS_TAG is ignored, and the branch condition is considered.

Examples for conditional deployments #

This deploys using a custom script deploy.sh, only for builds on the branches staging and production.

deploy:
  provider: script
  script: deploy.sh
  on:
    all_branches: true
    condition: $TRAVIS_BRANCH =~ ^(staging|production)$

This deploys using custom scripts deploy_production.sh and deploy_staging.sh depending on the branch that triggered the job.

deploy:
  - provider: script
    script: deploy_production.sh
    on:
      branch: production
  - provider: script
    script: deploy_staging.sh
    on:
      branch: staging

This deploys to S3 only when $CC is set to gcc.

deploy:
  provider: s3
  access_key_id: <encrypted access_key_id>
  secret_access_key: <encrypted secret_access_key>
  bucket: <bucket>
  on:
    condition: $CC = gcc