Using Hugo with Travis CI on GitHub Pages

In this blog post I will show how to build your static website with Hugo and deploy it to GitHub pages automatically using Travis CI. This can have a lot of benefits: For example, you can fix typo's directly from the Github web interface from your phone (without editing raw HTML). I kept the whole setup as minimal as possible. Hence, no bash script or travis command line tools are required.

Posted on 2017, May 26
3 mins read

Using Hugo with Travis CI on GitHub Pages

Introduction

In this blog post I will show how to build your static website with Hugo and deploy it to GitHub pages automatically using Travis CI.

This can have a lot of benefits: For example, you can fix typo’s directly from the Github web interface from your phone (without editing raw HTML).

Due to various reasons I decided to use different repositories rather than one repo with different branches.

Also, I kept the whole setup as minimal as possible. Hence, no bash script or travis command line tools are required.

Travis CI setup

travis.yml

First of all, you will need to add a .travis.yml file to the root of your source directory. Please be aware that your operating system may hide the file.

Paste this into your .travis.yml file and edit it as necessary (instrucions provided).

language: go
go:
- master # This uses automatically the latest version of go
install:
- go get github.com/spf13/hugo # This provides the latest version of Hugo to Travis CI
script:
- hugo # This commands builds your website on travis
deploy:
local_dir: public # Default static site output dir for Hugo
repo: <yourusername>/<yourusername>.github.io # This is the slug of the repo you want to deploy your site to
target_branch: master # GitHub pages branch to deploy to (in other cases it can be gh-pages)
provider: pages
skip_cleanup: true
github_token: $GITHUB_TOKEN # This is the authentication which you will setup in the next step in travis-ci dashboard
email: yourmail@mail.com
name: "Your username"
on:
branch: master