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
.