Skip to content

Commit 1e48906

Browse files
committed
Fix wait-for-job-finish script
1 parent 8b45f4a commit 1e48906

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

.circleci/config.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,10 @@ commands:
199199
working_directory: integration-tests
200200
name: Slack notification on dev branch only
201201
command: |
202-
if [ "$CIRCLE_NODE_INDEX" -eq 0 ] && [ "$CIRCLE_BRANCH" = "dev" ]; then
202+
if [ "$CIRCLE_BRANCH" = "alex-ci-testing" ]; then
203203
bash ../.circleci/wait-for-job-finish.sh
204204
node --require ../.pnp.cjs ./slack/notify-circleci-test-results.js
205205
fi
206-
no_output_timeout: 30m
207206
when: always
208207

209208
jobs:

.circleci/wait-for-job-finish.sh

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
77
set -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
914
counter=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
1218
while [ "$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))
2335
done
2436

25-
echo "Waited total $counter seconds"
26-
date
27-
2837
# Something is wrong. Log response for error troubleshooting
2938
curl -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."
3140
exit 1

0 commit comments

Comments
 (0)