GitHub Pages Deployment
This page documents deployments using the dpl v2. Please see our blog post for details. You can check previous dpl v1 documentation here.
Travis CI can deploy to GitHub Pages after a successful build.
For a minimal configuration, add the following to your .travis.yml
:
deploy:
provider: pages:git
token: <encrypted token>
edge: true # opt in to dpl v2
Alternatively, you can use deploy_key
:
deploy:
provider: pages:git
deploy_key: <deploy_key>
You can use a personal access token
with the public_repo
or repo
scope (repo
is required for private repositories).
Status #
Support for deployments to GitHub Pages is stable.
Known options #
Use the following options to further configure the deployment. Either token
or deploy_key
are required.
repo |
Repo slug — type: string, default: repo slug |
token |
GitHub token with repo permission — secret, type: string, alias: github_token |
deploy_key |
Path to a file containing a private deploy key with write access to the repository — type: string, see: https://developer.github.com/v3/guides/managing-deploy-keys/#deploy-keys |
target_branch |
Branch to push force to — type: string, default: gh-pages |
keep_history |
Create incremental commit instead of doing push force — type: boolean, default: true |
commit_message |
type: string, default: Deploy %{project_name} to %{url}:%{target_branch} |
allow_empty_commit |
Allow an empty commit to be created — type: boolean, requires: keep_history |
verbose |
Be verbose about the deploy process — type: boolean |
local_dir |
Directory to push to GitHub Pages — type: string, default: . |
fqdn |
Write the given domain name to the CNAME file — type: string |
project_name |
Used in the commit message only (defaults to fqdn or the current repo slug) — type: string |
name |
Committer name — type: string, note: defaults to the current git commit author name |
email |
Committer email — type: string, note: defaults to the current git commit author email |
committer_from_gh |
Use the token’s owner name and email for the commit — type: boolean, requires: token |
deployment_file |
Enable creation of a deployment-info file — type: boolean |
url |
type: string, alias: github_url , default: github.com |
Shared options #
strategy |
GitHub Pages deployment strategy — type: string, default: git , known values: api , git |
cleanup |
Clean up build artifacts from the Git working directory before the deployment — type: boolean |
run |
Commands to execute after the deployment finished successfully — type: string or array of strings |
Environment variables #
All options can be given as environment variables if prefixed with GITHUB_
or PAGES_
.
For example, token
can be given as
GITHUB_TOKEN=<token>
orPAGES_TOKEN=<token>
Interpolation variables #
The following variables are available for interpolation on commit_message
:
deploy_key
email
fqdn
git_author_email
git_author_name
git_branch
git_commit_author
git_commit_msg
git_sha
git_tag
local_dir
name
project_name
repo
target_branch
url
Interpolation uses the syntax %{variable-name}
. For example,
"Current commit sha: %{git_sha}"
would result in a string with the
current Git sha embedded.
Furthermore, environment variables present in the current build environment can be used through standard Bash variable interpolation. For example: “Current build number: ${TRAVIS_BUILD_NUMBER}”. See here for a list of default environment variables set.
Securing secrets #
Secret option values should be given as either encrypted strings in your build
configuration (.travis.yml
file) or environment variables in your repository
settings.
Environment variables can be set on the settings page of your repository, or
using travis env set
:
travis env set GITHUB_TOKEN <token>
In order to encrypt option values when adding them to your .travis.yml
file
use travis encrypt
:
travis encrypt <token>
Or use --add
to directly add it to your .travis.yml
file. Note that this command has to be run in your repository’s root directory:
travis encrypt --add deploy.token <token>
Set up the GitHub token #
Pull Requests #
Note that pull request builds skip the deployment step altogether.