@@ -6,26 +6,35 @@ set -o nounset
66# Use the error status of the first failure, rather than that of the last item in a pipeline. Also fail explicitly on any exit code.
77set -eo pipefail
88
9+ trap ' s=$?; echo -e >&2 "\nError in $0:\nat line "$LINENO": $BASH_COMMAND"; exit $s' ERR
10+
11+ echo " Starting wait-for-job-finish script"
12+
13+ date
914counter=0
15+ URL_BASE=" https://circleci.com/api/v2/project/github/DataBiosphere/terra-ui"
1016
1117# Wait up to 25 minutes for job to finish. A job can run on multiple nodes: parallelism > 1
1218while [ " $counter " -le 1500 ]; do
13- # Find number of nodes in running
14- job_detail=$( curl -s " https://circleci.com/api/v2/project/github/DataBiosphere/terra-ui/job/$CIRCLE_BUILD_NUM " )
15- job_running_nodes_count=$( echo " $job_detail " | jq -r ' [.parallel_runs[] | select(.status == "running") | select(.index != ' " $CIRCLE_NODE_INDEX " ' )] | length' )
16-
17- if [ " $job_running_nodes_count " -eq 0 ]; then
18- exit 0
19+ # Get job details
20+ job_detail=$( curl -s " $URL_BASE /job/$CIRCLE_BUILD_NUM " )
21+
22+ # Wait for all nodes with status==running excluding self node
23+ nodes=$( echo " $job_detail " | jq -r ' .parallel_runs[]' )
24+ running_nodes=$( echo " $nodes " | jq -r --arg IDX " $CIRCLE_NODE_INDEX " ' select(.status=="running") | select(.index|tostring!=$IDX)' )
25+ count=$( echo " $running_nodes " | grep -c -e " running" || test $? = 1; )
26+ if [ " $count " -eq 0 ]; then
27+ echo " Checking from NODE_INDEX #$CIRCLE_NODE_INDEX : Parallel running nodes have finished. Waited $counter seconds."
28+ echo " $nodes "
29+ exit 0
1930 fi
2031
32+ echo " Waiting for parallel running nodes to finish. Sleep 10 seconds."
2133 sleep 10
2234 counter=$(( $counter + 10 ))
2335done
2436
25- echo " Waited total $counter seconds"
26- date
27-
2837# Something is wrong. Log response for error troubleshooting
2938curl -s " https://circleci.com/api/v2/project/github/DataBiosphere/terra-ui/job/$CIRCLE_BUILD_NUM " | jq -r ' .'
30- echo " ERROR: Exceeded maximum waiting time 25 minutes."
39+ echo " ERROR: Exceeded maximum wait time 25 minutes."
3140exit 1
0 commit comments