Last active
February 20, 2023 08:24
-
-
Save alexrashed/9dc04e78cff737b7cbb42861b6555221 to your computer and use it in GitHub Desktop.
await circle ci workflow to finish
This file contains 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 | |
# 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