Skip to content

Instantly share code, notes, and snippets.

@drogus
Created June 11, 2015 12:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drogus/ddfb42c67903194f446f to your computer and use it in GitHub Desktop.
Save drogus/ddfb42c67903194f446f to your computer and use it in GitHub Desktop.

Requesting a build through the API can be done by sending a POST request to a /repo/{slug|id}/requests path.

Here is script for sending minimal request to a travis-ci/travis-core repository, for a master branch:

body='{
"request": {
  "branch":"master"
}'

curl -s -X POST \
  -H "Content-Type: application/json" \
  -H "Accept: application/json" \
  -H "Travis-API-Version: 3" \
  -H "Authorization: token xxxxxx" \
  -d "$body" \
  https://api.travis-ci.org/repo/travis-ci%2Ftravis-core/requests

This request would trigger a build for the last commit on the master branch of the travis-ci/travis-core repository. It will use a .travis.yml file for the commit. You can also override the commit message or the config by passing message and config attributes respectively:

body='{
"request": {
  "message": "Override the commit message: this is an api request",
  "branch":"master",
  "config": {
    "env": {
      "matrix": ["TEST=unit"]
    },
    "script": "echo FOO"
  }
}'

curl -s -X POST \
  -H "Content-Type: application/json" \
  -H "Accept: application/json" \
  -H "Travis-API-Version: 3" \
  -H "Authorization: token xxxxxx" \
  -d "$body" \
  https://api.travis-ci.org/repo/travis-ci%2Ftravis-core/requests

In this example a config from the .travis.yml file will be merged with a config from the request body. Keys in the request's config will override any keys existing in the .travis.yml.

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