Link Search Menu Expand Document

Here is the documentation to set up CI with Travis and Rollbar to your project!

  1. Setting up Travis
  2. Rollbar
    1. Rollbar deploy tracking feature via Travis

Setting up Travis

Add these lines to your Gemfile:

gem 'travis'
gem 'rspec'

Then run: bundle install

You can either create the travis.yml file or run travis init

create a file called config/database.yml.travis with the following contents

  adapter: postgresql
  database: travis_ci_test

This is how travis.yml file should look:

  postgresql: '10'
    - postgresql-server-dev-10
language: ruby
cache: bundler
- psql -c 'create database travis_ci_test;' -U postgres
- cp config/database.yml.travis config/database.yml
- bundle exec rake db:test:prepare
- bundle exec rspec spec
- redis-server
- provider: cloud66
  	secure: place your encrypted key
    branch: staging
- provider: cloud66
  	secure: place your encrypted key
    branch: master
  - master
  - staging


  1. Find the rollbar access token and add it as a Rails secure credential under rollbar/access_token
  2. Add the following content to config/initializers/rollbar.rb
Rollbar.configure do |config|
  # Without configuration, Rollbar is enabled in all environments.
  # To disable in specific environments, set config.enabled=false.

  config.access_token = Rails.application.credentials.dig(:rollbar, :access_token)
	ENV['ROLLBAR_ACCESS_TOKEN'] = config.access_token # so the script in the second part of the deployment works properly

  # Here we'll disable in 'test':
  if Rails.env.development? || Rails.env.test?
    config.enabled = false

  # By default, Rollbar will try to call the `current_user` controller method
  # to fetch the logged-in user object, and then call that object's `id`
  # method to fetch this property. To customize:
  # config.person_method = "my_current_user"
  # config.person_id_method = "my_id"

  # Additionally, you may specify the following:
  # config.person_username_method = "username"
  # config.person_email_method = "email"

  # If you want to attach custom data to all exception and message reports,
  # provide a lambda like the following. It should return a hash.
  # config.custom_data_method = lambda { {:some_key => "some_value" } }

  # Add exception class names to the exception_level_filters hash to
  # change the level that exception is reported at. Note that if an exception
  # has already been reported and logged the level will need to be changed
  # via the rollbar interface.
  # Valid levels: 'critical', 'error', 'warning', 'info', 'debug', 'ignore'
  # 'ignore' will cause the exception to not be reported at all.
  # config.exception_level_filters.merge!('MyCriticalException' => 'critical')
  # You can also specify a callable, which will be called with the exception instance.
  # config.exception_level_filters.merge!('MyCriticalException' => lambda { |e| 'critical' })

  # Enable asynchronous reporting (uses girl_friday or Threading if girl_friday
  # is not installed)
  # config.use_async = true
  # Supply your own async handler:
  # config.async_handler = { |payload|
  # { Rollbar.process_from_async_handler(payload) }
  # }

  # Enable asynchronous reporting (using sucker_punch)
  # config.use_sucker_punch

  # Enable delayed reporting (using Sidekiq)
  # config.use_sidekiq
  # You can supply custom Sidekiq options:
  # config.use_sidekiq 'queue' => 'default'

  # If your application runs behind a proxy server, you can set proxy parameters here.
  # If https_proxy is set in your environment, that will be used. Settings here have precedence.
  # The :host key is mandatory and must include the URL scheme (e.g. 'http://'), all other fields
  # are optional.
  # config.proxy = {
  #   host: 'http://some.proxy.server',
  #   port: 80,
  #   user: 'username_if_auth_required',
  #   password: 'password_if_auth_required'
  # }

  # If you run your staging application instance in production environment then
  # you'll want to override the environment reported by `Rails.env` with an
  # environment variable like this: `ROLLBAR_ENV=staging`. This is a recommended
  # setup for Heroku. See:
  config.environment = ENV['ROLLBAR_ENV'].presence || Rails.env

Rollbar deploy tracking feature via Travis

To keep track of deployements in rollbar:

  • Add this code to your travis.yml file
- ./ succeeded
- export APPLICATION_NAME=application name
- export DEPLOYENV=$(if [ "${TRAVIS_BRANCH}" == "staging" ]; then echo "staging";
  else echo "production"; fi)
- export AUTHOR_NAME="$(git log -1 $TRAVIS_COMMIT --pretty="%aN")"
- ./ started
- export DEPLOY_ID="$(while read -r line; do echo "$line"; done < ~/deploy_id_from_rollbar)"
  • create a new file called under project folder with the following content:
function start_deployment() {
  deploy_id=`curl --request POST --url \
  			--form access_token=$ROLLBAR_ACCESS_TOKEN \
  			--form environment=$DEPLOYENV \
  			--form revision=$TRAVIS_COMMIT \
  			--form comment="Deployment started in $DEPLOYENV for $APPLICATION_NAME" \
  			--form status=started \
  			--form local_username=$AUTHOR_NAME | python -c 'import json, sys; obj = json.load(sys.stdin); print obj["data"]["deploy_id"]'`
  echo "$deploy_id" >> ~/deploy_id_from_rollbar

function set_deployment_success() {
  curl --request PATCH --url "$DEPLOY_ID?access_token=$ROLLBAR_ACCESS_TOKEN" --data '{"status": "succeeded"}'

if [ "$1" == "started" ]
  echo "$1"
  • Run $ chmod 755 home/pathname/ to make the file executable: