For reference, this is the way I managed to do it as of March 2016 starting with the link mentioned in this comment:
-
Added
HEROKU_API_LOGIN
(fromheroku auth:whoami
) andHEROKU_API_KEY
(fromheroku auth:token
) as protected ENV variables in the travis.org build settings. Alternatively, they can be added in the.travis.yml
with:travis encrypt HEROKU_API_LOGIN ="$(heroku auth:whoami)" --add travis encrypt HEROKU_API_KEY="$(heroku auth:token)" --add
-
Added following lines to the
.travis.yml
:sudo: required before_deploy: - ./.travis_before_deploy.sh after_deploy: - ./.travis_after_deploy.sh
sudo: required
is required since the use of container based build environments by default. -
Created the file
.travis_before_deploy.sh
with the following content:#!/bin/bash set -e -o pipefail if [ "${TRAVIS_BRANCH}" == "master" ]; then TARGET_APP_NAME="your_app_name" echo "Setting up '~/.ssh/config' to work with heroku." cat >> ~/.ssh/config <<EOF Host heroku.com StrictHostKeyChecking no CheckHostIP no UserKnownHostsFile=/dev/null EOF # DOC: https://devcenter.heroku.com/articles/authentication#usage-examples cat >> ~/.netrc <<EOF machine api.heroku.com login ${HEROKU_API_LOGIN} password ${HEROKU_API_KEY} EOF chmod 600 ~/.netrc echo "Installing heroku toolbelt" wget -qO- https://toolbelt.heroku.com/install-ubuntu.sh | sh echo "Setting maintenance mode 'on' on heroku's app" heroku maintenance:on --app "${TARGET_APP_NAME}" echo "Caturing DB backup from heroku's app" # DOC: https://devcenter.heroku.com/articles/heroku-postgres-backups#creating-a-backup heroku pg:backups capture --app "${TARGET_APP_NAME}" fi
-
Created the file
.travis_after_deploy.sh
with the following content:#!/bin/bash set -e -o pipefail if [ "${TRAVIS_BRANCH}" == "master" ]; then TARGET_APP_NAME="your_app_name" echo "Setting maintenance mode 'off' on heroku's app" heroku maintenance:off --app "${TARGET_APP_NAME}" echo "Application ready again. YAY!" fi