Skip to content

Commit

Permalink
Convert output from list-tasks to quoted and comma separated list of …
Browse files Browse the repository at this point in the history
…ARNs
  • Loading branch information
Warren-Johnson-TID committed May 1, 2024
1 parent 648ecb8 commit 185e258
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions deploy-ecs/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,17 @@ while [ "${deployment_finished}" = "false" ]; do
# extract deployment id
new_deployment_id="$(echo "${new_deployment}" | jq -r '.id')"
# find any tasks that may have stopped unexpectedly
stopped_tasks="$(aws ecs list-tasks --cluster "${ECS_CLUSTER}" --started-by "${new_deployment_id}" --desired-status "STOPPED" | jq -r '.taskArns')"
stopped_task_count="$(echo "${stopped_tasks}" | jq -r 'length')"
# this should provide a list of arns (if any) that are quoted and space separated
# i.e. "arn:aws:ecs:us-west-2:123456789012:task/a1b2c3d4-5678-90ab-cdef-11111EXAMPLE" "arn:aws:ecs:us-west-2:123456789012:task/a1b2c3d4-5678-90ab-cdef-22222EXAMPLE"
stopped_tasks="$(aws ecs list-tasks --cluster "${ECS_CLUSTER}" --started-by "${new_deployment_id}" --desired-status "STOPPED" | jq -r '.taskArns[] | "\"\(. )\""' | tr '\n' ' ')"

# count number of quotes and divide by two
stopped_task_count=$(echo "$stopped_tasks" | grep -o '\"' | wc -l)
stopped_task_count=$((stopped_task_count / 2))

if [ "${stopped_task_count}" -gt "0" ]; then
# if there are stopped tasks, print the reason they stopped and then exit
stopped_task_list="$(echo "${stopped_tasks}" | jq -r 'join(",")')"
stopped_reasons="$(aws ecs describe-tasks --cluster "${ECS_CLUSTER}" --tasks "${stopped_task_list}" | jq -r '.tasks[].stoppedReason')"
stopped_reasons="$(aws ecs describe-tasks --cluster "${ECS_CLUSTER}" --tasks "${stopped_tasks}" | jq -r '.tasks[].stoppedReason')"
echo "The deployment failed because one or more containers stopped running. The reasons given were:"
echo "${stopped_reasons}"
exit 1
Expand Down

0 comments on commit 185e258

Please sign in to comment.