Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Auto deploy blog generated by jekyll with jekyll-archives

Auto-Deploying Blogs to GitHub Pages with Travis CI

GitHub Pages doesn't support jekyll-archives now PR. We can use Travis CI to build it and push to gh-pages branch.

There is already some gists talks about this topic using bash. However, Travis now support deploy in .travis.yml , which is super easy to set up. (Deploying to GitHub Pages is experimental now [2018.07.25])

Create .travis.yml File

Here is an example.

language: ruby
cache: bundler
sudo: false
rvm: 2.5

install:
  - gem install bundler
  - bundle install

script:
  - bundle exec jekyll build

after_success:
  - touch ./_site/.nojekyll

deploy:
  provider: pages
  skip-cleanup: true
  keep-history: true
  on:
    branch: master
  github-token: $GITHUB_TOKEN
  local-dir: _site
  committer-from-gh: true

For the details about deploy , check Travis docs .

For now, you have already done most of the work.

Set GitHub Token

To push files to your repo@gh-pages , Travis needs your authority. This means you need to offer a personal GitHub token.

You can choose to set this in travis-ci.org/repo/settings as an environment variable or pass it to .travis.yml as an encrypted variable.

Create GitHub Tokens

Open https://github.com/settings/tokens and click Generate new token . Just select repo is enough. You can get details from GitHub Help .

Travis Environment Variable

This can be set in your repo's travis page, More options -> settings , or just add /settings to the URL.

The variable name should be the same with github-token in .travis.yml .

Encrypted Variables

Details can be found in Travis Docs .

Finally

Deploying is triggered depending on your repo's travis settings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment