GitHub Releases Uploading
Travis CI can automatically upload assets from your
$TRAVIS_BUILD_DIR to git tags on your GitHub repository.
For a minimal configuration, add the following to your
deploy: provider: releases api_key: "GITHUB OAUTH TOKEN" file: "FILE TO UPLOAD" skip_cleanup: true on: tags: true
Make sure you have
true, otherwise Travis CI will delete all the files created during the build, which will probably delete what you are trying to upload.
GitHub Releases uses git tags. If the build commit does not have any tags, one will be created in the form of
* is a random hex string.
If this is not what you want, either set your build to deploy only when the build already has a tag using
on.tags: true as shown in the previous example
.travis.yml, or tag the commit with
git tag in
before_deploy: # Set up git user name and tag this commit - git config --local user.name "YOUR GIT USER NAME" - git config --local user.email "YOUR GIT USER EMAIL" - git tag "$(date +'%Y%m%d%H%M%S')-$(git log --format=%h -1)" deploy: provider: releases api_key: "GITHUB OAUTH TOKEN" file: "FILE TO UPLOAD" skip_cleanup: true
If you need to overwrite existing files, add
overwrite: true to the
deploy section of your
You can also use the Travis CI command line client to configure your
travis setup releases
Or, if you’re using a private repository:
travis setup releases --pro
When working with GitHub Releases, it is important to understand how the deployment is triggered
Authenticating with an OAuth token
The recommended way to authenticate is to use a GitHub OAuth token. It must have the
repo scope to upload assets. Instead of setting it up manually, it is highly recommended to use
travis setup releases, which automatically creates and encrypts a GitHub oauth token with the correct scopes.
This results in something similar to:
deploy: provider: releases api_key: secure: YOUR_API_KEY_ENCRYPTED file: "FILE TO UPLOAD" skip_cleanup: true on: tags: true
Authentication with a Username and Password
You can also authenticate with your GitHub username and password using the
password options. This is not recommended as it allows full access to your GitHub account but is simplest to setup. It is recommended to encrypt your password using
travis encrypt "GITHUB PASSWORD" --add deploy.password. This example authenticates using a username and password.
deploy: provider: releases user: "GITHUB USERNAME" password: "GITHUB PASSWORD" file: "FILE TO UPLOAD" skip_cleanup: true on: tags: true
Deploying to GitHub Enterprise
If you wish to upload assets to a GitHub Enterprise repository, you must override the
$OCTOKIT_API_ENDPOINT environment variable with your GitHub Enterprise API endpoint:
http(s)://"GITHUB ENTERPRISE HOSTNAME"/api/v3/
You can configure this in Repository Settings or via your
env: global: - OCTOKIT_API_ENDPOINT="GITHUB ENTERPRISE API ENDPOINT"
Uploading Multiple Files
You can upload multiple files using yml array notation. This example uploads two files.
deploy: provider: releases api_key: secure: YOUR_API_KEY_ENCRYPTED file: - "FILE 1" - "FILE 2" skip_cleanup: true on: tags: true
You can also enable wildcards by setting
true. This example
includes all files in a given directory.
deploy: provider: releases api_key: "GITHUB OAUTH TOKEN" file_glob: true file: directory/* skip_cleanup: true on: tags: true
You can deploy only when certain conditions are met.
See Conditional Releases with
Running commands before or after release
Sometimes you want to run commands before or after releasing a gem. You can use the
after_deploy stages for this. These will only be triggered if Travis CI is actually pushing a release.
before_deploy: "echo 'ready?'" deploy: .. after_deploy: - ./after_deploy_1.sh - ./after_deploy_2.sh
.travis.yml are passed through to Octokit API, so you can use any valid Octokit option.
Note that formatting in
body is not preserved.