The Cookbook with Rails

Below is a practical Travis CI use case for Rails, we hope you enjoy and we hope to get you building even faster!

Let’s put Travis on Rails!

You’ll obviously want to signup for Travis, be sure to sync your account, open your Gemfile and add:

gem 'travis' 

Run any migrations you may need to make, then:

bundle install

In this use case, we are creating the .travis.yml via:

travis init

You don’t in theory need to specify a Ruby version, Travis will look at your ruby-, but you can definitely specify a Ruby version if you chose to:

language: ruby
dist: xenial
rvm: 2.5.8

That tells Travis what language (Ruby), what dist you’ll be using (also can be changed) and rvm the version of Ruby you’ll be using. You can now add script which is commands you’re telling Travis to run when you triggered a build, so it could look like the following:

 — bundle install — jobs=3 — retry=3
 — bundle exec rake db:create
 — bundle exec rake db:migrate
 — bundle exec rspec

You can then check your .travis.yml’s validity via the linting online application Travis Lint, or do it manually:

 travis lint

Then commit changes and see your Rails app build! We push to GitHub, we’ll be doing this in a variety of different ways in the upcoming Cookbook entries, so you’ll have a choice on how you’d like to deploy!

 git init
 git add . 
 git commit -m "Travis build" 
 git remote add origin remote repository URL
 git remote -v 
 git push -u origin master

That’s it, you’re setup. Travis is on Rails. We have new recipes every week, make sure you come back next week for a practical way of using Travis for beginners.