-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtrigger-travis.sh
executable file
·43 lines (38 loc) · 1.13 KB
/
trigger-travis.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/bash
## brief: trigger a downstream travis build
## see: travis API documentation
# variables
USER=$1
REPO=$2
BRANCH=$3
TOKEN=$4
MESSAGE=",\"message\": \"Triggered from upstream build of $TRAVIS_REPO_SLUG by commit "`git rev-parse --short HEAD`"\""
# for debugging
# echo "USER=$USER"
# echo "REPO=$REPO"
# echo "TOKEN: ${array[${#array[@]}-1]}"
# echo "BRANCH=$BRANCH"
# echo "MESSAGE=$MESSAGE"
# curl POST request content body
BODY="{
\"request\": {
\"branch\":\"$BRANCH\"
$MESSAGE
}}"
# make a POST request with curl (note %2F could be replaced with
# / and additional curl arguments, however this works too!)
curl -s -X POST \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "Travis-API-Version: 3" \
-H "Authorization: token ${TOKEN}" \
-d "$BODY" \
https://api.travis-ci.org/repo/${USER}%2F${REPO}/requests \
| tee /tmp/travis-request-output.$$.txt
if grep -q '"@type": "error"' /tmp/travis-request-output.$$.txt; then
cat /tmp/travis-request-output.$$.txt
exit 1
elif grep -q 'access denied' /tmp/travis-request-output.$$.txt; then
cat /tmp/travis-request-output.$$.txt
exit 1
fi