Script Deployment

This page documents deployments using dpl v1 which is currently the legacy version. The dpl v2 is released, and we recommend useig it. Please see our blog post for details. dpl v2 documentation can be found here.

If your deployment needs more customization than the after_success method allows, use a custom script.

The following example runs scripts/deploy.sh on the develop branch of your repository if the build is successful.

deploy:
  provider: script
  script: bash scripts/deploy.sh
  on:
    branch: develop

If you need to run multiple commands, write a executable wrapper script that runs them all. The argument to script: in the script deployment provider needs to be a single command.

If the script returns a nonzero status, deployment is considered a failure, and the build will be marked as “errored”.

Pass Arguments to the Script #

It is possible to pass arguments to a script deployment.

deploy:
  # deploy develop to the staging environment
  - provider: script
    script: bash scripts/deploy.sh staging
    on:
      branch: develop
  # deploy master to production
  - provider: script
    script: bash scripts/deploy.sh production
    on:
      branch: master

The script has access to all the usual environment variables.

deploy:
  provider: script
  script: bash scripts/deploy.sh production $TRAVIS_TAG
  on:
    tags: true
    all_branches: true

Ruby Version #

To ensure that deployments run consistently, we use the version of Ruby that is pre-installed on all of our build images, which may change when images are updated.

  • The travis_internal_ruby function prints the exact pre-installed Ruby version

If you need to run a command that requires a different Ruby version than the pre-installed default, you need to set it explicitly:

deploy:
  provider: script
  script: rvm use $TRAVIS_RUBY_VERSION do script.rb