Created
December 11, 2015 21:31
-
-
Save davedash/4a80ccff1a8f1b128b2e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -e | |
CIRCLE_TOKEN=PRIVATE | |
API_ROOT=https://circleci.com/api/v1 | |
_project=PRIVATE | |
_branch=circle-ci-test | |
URL=${API_ROOT}/project/${_project}/tree/${_branch}?circle-token=${CIRCLE_TOKEN} | |
echo ${CIRCLE_TOKEN} | |
function check_busy { | |
set +e | |
curl -sH'Accept: application/json' \ | |
${API_ROOT}/recent-builds\?circle-token\=${CIRCLE_TOKEN} | \ | |
jq ".[]|.status" | \ | |
grep -q running | |
CIRCLE_NOT_RUNNING=${?} | |
set -e | |
if [[ "${CIRCLE_NOT_RUNNING}" -eq 0 ]]; then | |
echo "Circle is busy." | |
exit 0 | |
fi | |
} | |
function trigger_build { | |
echo "Triggering build." | |
curl -s \ | |
--header "Accept: application/json" \ | |
--header "Content-Type: application/json" \ | |
--data "${post_data}" \ | |
--request POST ${URL} > /dev/null | |
} | |
function check_last_build { | |
STATUS=$(curl -s \ | |
--header "Accept: application/json" \ | |
--header "Content-Type: application/json" \ | |
--request GET ${URL}\&filter=completed | jq -r ".[0].status") | |
# Use tags | |
echo "circle_ci_test.${STATUS}:1|c" | \ | |
nc -w 1 -u 127.0.0.1 8125 | |
} | |
function main { | |
check_busy | |
trigger_build | |
check_last_build | |
} | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment