Skip to content

Instantly share code, notes, and snippets.

@ykazakov
Last active April 8, 2020 21:49
Show Gist options
  • Save ykazakov/33a86f5055888342f6a32d829fc02fa9 to your computer and use it in GitHub Desktop.
Save ykazakov/33a86f5055888342f6a32d829fc02fa9 to your computer and use it in GitHub Desktop.
Trigger AppVeyor builds using the REST API
#!/bin/sh
# Trigger AppVeyor builds using the REST API
# Usage:
# trigger-appveyor.sh [--branch BRANCH] APPVEYORUSER APPVEYORPROJECT AUTHORIZATION_TOKEN
# Based on the example from
# https://www.appveyor.com/docs/api/projects-builds/#start-build-of-branch-most-recent-commit
# Tand on the script trigger-travis.sh from
# https://github.com/plume-lib/trigger-travis
if [ "$#" -lt 3 ] || [ "$#" -gt 5 ]; then
echo "Wrong number of arguments $# to trigger-appveyor.sh; run like:"
echo " trigger-appveyor.sh [--branch BRANCH] APPVEYORUSER APPVEYORPROJECT AUTHORIZATION_TOKEN" >&2
exit 1
fi
if [ "$1" = "--branch" ] ; then
shift
BRANCH="$1"
shift
else
BRANCH=master
fi
USER=$1
shift
REPO=$1
shift
TOKEN=$1
body="{
\"accountName\": \"$USER\",
\"projectSlug\": \"$REPO\",
\"branch\": \"$BRANCH\",
}"
curl -s -X POST \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d "$body" \
https://ci.appveyor.com/api/account/${USER}/builds \
| tee /tmp/appveyor-request-response.$$.txt
if grep -q '"@type": "error"' /tmp/appveyor-request-response.$$.txt; then
exit 1
fi
if grep -q 'access denied' /tmp/appveyor-request-response.$$.txt; then
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment