Skip to content

Instantly share code, notes, and snippets.

@alexrashed
Last active February 20, 2023 08:24
Show Gist options
  • Save alexrashed/9dc04e78cff737b7cbb42861b6555221 to your computer and use it in GitHub Desktop.
Save alexrashed/9dc04e78cff737b7cbb42861b6555221 to your computer and use it in GitHub Desktop.
await circle ci workflow to finish
#!/bin/bash
# Simple bash script to wait for a worfklwo to finish (f.e. to trigger a notification)
# Based on https://github.com/rockymadden/circleci-cli
token=$CIRCLECI_TOKEN
resolution=15
workflow=$1
function await() {
function go() {
local rsp ; rsp=$(curl -f -s -H 'Accept: application/json' -u "${token}:" "https://circleci.com/api/v2/workflow/${workflow}")
case "$?" in
0)
local outcome=$(echo ${rsp} | jq -r '.status')
case "${outcome}" in
running) sleep "${resolution}" ; go ;;
success) echo ${rsp} | jq ;;
*) echo ${rsp} | jq ;;
esac
;;
*) return 1 ;;
esac
}
go ; return $?
}
await
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment