Using Travis CI to build and deploy sites
For those who have used Jekyll, you would know that each time you make changes to your blog, you have to regenerate the static pages, perhaps test them, and then deploy the changes to your hosting provider, which in my case is Surge. Now, Travis CI does all that for me automatically whenever I push an update to GitHub!
Here’re what I did:
- Enable Travis builds for your GitHub repository. Enable
Build only if .travis.yml is presentin the settings page
SURGE_TOKENvariables with the
- Create a build and test script, and commit it to your repository. For some reasons, Travis CI had issues with a few of my external links, so I disabled the external link checker with the
--disable-externaloption. Make sure you fix all the issues that
htmlprooferhas found until you see the
HTML-Proofer finished successfullymessage
set -e # halt script on error
bundle exec jekyll build
bundle exec htmlproofer ./_site --disable-external
# bundle exec htmlproofer ./_site
- Update your Gemfile so that Travis can automatically install all the Ruby dependencies with
bundle install. For example,
$ grep -v ^# Gemfile
- 2.3.0 # ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin15]
- chmod +x ./script/cibuild
- npm install --global surge
- NOKOGIRI_USE_SYSTEM_LIBRARIES=true # speeds up installation of
sudo: false # route your build to the container-based infrastructure
# for a faster build
surge -p ./_site/
When Travis CI detects a push to GitHub, it will set up a build environment in a clean VM, make
./script/cibuild an executable, install
surge, run the script only on the
source branch, and if the build is successful, deploy the blog to Surge.
That’s all you have to do. Hope you find these steps useful.
Originally published at temasek.org on May 10, 2016.