Skip to content

Instantly share code, notes, and snippets.

@jirutka
Last active March 25, 2018 04:48
Show Gist options
  • Save jirutka/344c98dccce7cc851d0a to your computer and use it in GitHub Desktop.
Save jirutka/344c98dccce7cc851d0a to your computer and use it in GitHub Desktop.
This script triggers (re)build of the specified project on Travis CI.
#!/bin/bash
#
# This script triggers (re)build of the specified project on Travis CI.
#
# It expects Travis token to be set in environment variable TRAVIS_TOKEN.
# To get a token, run: travis token.
#
# Usage:
# travis-build-dependent <REPO_SLUG> [<BRANCH>]
#
# REPO_SLUG the repository to build, typically username/project-name.
# BRANCH the branch to build (default is 'master').
message="Triggered by successful build of $TRAVIS_REPO_SLUG"
repo_slug=$1
branch=${2:-master}
body="{
'request': {
'message': '$message',
'branch': '$branch'
}
}"
echo "Triggering build of $repo_slug branch $branch on Travis."
curl -X POST \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "Travis-API-Version: 3" \
-H "Authorization: token $TRAVIS_TOKEN" \
-d "${body//\'/\"}" \
https://api.travis-ci.org/repo/${repo_slug/\//%2F}/requests
@hroncok
Copy link

hroncok commented Jun 26, 2015

This works out of the box when run on Travis from a repository of the same owner? Or I need to save and encrypt my Travis token generated by travis token to .travis.yml of the project where this is invoked?

@jirutka
Copy link
Author

jirutka commented Aug 13, 2015

@hroncok Sorry for late response, Gist doesn’t have e-mail notifications…

Since Travis doesn’t expose $TRAVIS_TOKEN variable, that is used in this script, you need to store it (encrypted) in your .travis.yml. Is this a problem in your case?

@hroncok
Copy link

hroncok commented Aug 13, 2015

@jirutka I was thinking about personal token stored in team repo, but as long as you trust your mates and their security, it should be fine. Worst case, somebody breaks your Travis setup, should not be a big feal.

@hroncok
Copy link

hroncok commented Aug 13, 2015

I mean deal.

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