Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Query buildkit builds for changes since last
#!/usr/bin/env bash
set -euo pipefail
function builds() {
curl -s https://graphql.buildkite.com/v1 \
-H "Authorization: Bearer $GRAPHQL_KEY" \
-d '{
"query": "query SuccessfullBuilds { pipeline(slug: \"'"$BUILDKITE_ORGANIZATION_SLUG/$BUILDKITE_PIPELINE_SLUG"'\") { builds { edges { node { id commit message state } } } } }",
"variables": "{ }"
}'
}
function builds_with_state() {
jq -r '.data.pipeline.builds.edges[].node | select(.state == "'$1'") | .commit'
}
LAST_COMMIT=$(builds | builds_with_state "PASSED" | head -n 1)
FILES=$(git diff --name-only $LAST_COMMIT)
MATCH=functions*
for f in $FILES ; do
if [[ $f == $MATCH ]]; then
exit 0
fi
done
exit 1
@mblarsen

This comment has been minimized.

Copy link
Owner Author

@mblarsen mblarsen commented Apr 17, 2019

LAST_COMMIT = commit of last passed bulid
MATCH = in my case I want to exit successfully if something matches "functions" otherwise fail

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