|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Trigger a new Travis-CI job. |
| 4 | +# Ordinarily, a new Travis job is triggered when a commit is pushed to a |
| 5 | +# GitHub repository. The trigger-travis.sh script provides a programmatic |
| 6 | +# way to trigger a new Travis job. |
| 7 | + |
| 8 | +# To use this script to trigger a dependent build in Travis, do two things: |
| 9 | +# |
| 10 | +# 1. Set an environment variable TRAVIS_ACCESS_TOKEN by navigating to |
| 11 | +# https://travis-ci.org/MYGITHUBID/MYGITHUBPROJECT/settings |
| 12 | +# The TRAVIS_ACCESS_TOKEN environment variable will be set when Travis runs |
| 13 | +# the job, but won't be visible to anyone browsing https://travis-ci.org/. |
| 14 | +# |
| 15 | + |
| 16 | + |
| 17 | +TRAVIS_URL=travis-ci.org |
| 18 | +BRANCH=develop |
| 19 | +USER="utPLSQL" |
| 20 | +RESULT=1 |
| 21 | +declare -a REPO_MATRIX=("utPLSQL-java-api" "utPLSQL-v2-v3-migration" "utPLSQL-cli") |
| 22 | + |
| 23 | +TOKEN=$1 |
| 24 | + |
| 25 | +if [ -n "$TRAVIS_REPO_SLUG" ] ; then |
| 26 | + MESSAGE=",\"message\": \"Triggered by upstream build of $TRAVIS_REPO_SLUG commit "`git rev-parse --short HEAD`"\"" |
| 27 | +else |
| 28 | + MESSAGE=",\"message\": \"Triggered manually from shell\"" |
| 29 | +fi |
| 30 | + |
| 31 | +## For debugging: |
| 32 | +# echo "TOKEN=$TOKEN" |
| 33 | +# echo "MESSAGE=$MESSAGE" |
| 34 | + |
| 35 | +body="{ |
| 36 | +\"request\": { |
| 37 | + \"branch\":\"$BRANCH\" |
| 38 | + $MESSAGE |
| 39 | +}}" |
| 40 | + |
| 41 | +for DOWNSTREAM_BUILD in "${REPO_MATRIX[@]}"; do |
| 42 | + |
| 43 | + curl -s -X POST \ |
| 44 | + -H "Content-Type: application/json" \ |
| 45 | + -H "Accept: application/json" \ |
| 46 | + -H "Travis-API-Version: 3" \ |
| 47 | + -H "Authorization: token ${TOKEN}" \ |
| 48 | + -d "$body" \ |
| 49 | + https://api.${TRAVIS_URL}/repo/${USER}%2F${DOWNSTREAM_BUILD}/requests \ |
| 50 | + | tee ${DOWNSTREAM_BUILD}-output.txt |
| 51 | + |
| 52 | + if grep -q '"@type": "error"' ${DOWNSTREAM_BUILD}-output.txt; then |
| 53 | + #exit 1 |
| 54 | + RESULT=0 |
| 55 | + echo "" |
| 56 | + echo "Failed to start ${DOWNSTREAM_BUILD}" |
| 57 | + echo "" |
| 58 | + fi |
| 59 | + if grep -q 'access denied' ${DOWNSTREAM_BUILD}-output.txt; then |
| 60 | + #exit 1 |
| 61 | + RESULT=0 |
| 62 | + echo "" |
| 63 | + echo "Failed to start ${DOWNSTREAM_BUILD}" |
| 64 | + echo "" |
| 65 | + fi |
| 66 | + |
| 67 | +done |
| 68 | + |
| 69 | +if [[ RESULT -eq 0 ]]; then |
| 70 | + exit 1 |
| 71 | +fi |
0 commit comments