Skip to content

Commit f676f54

Browse files
authored
Merge pull request #14 from meirshal/exit-with-1-on-error
Exit with code 1 when command returned error or failed to execute
2 parents 33a693c + 3d9e68e commit f676f54

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

Diff for: aws-connect

+15-14
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ while getopts "a:d:c:f:g:w:n:t:r:p:o:x:shvl" OPTION; do
116116
;;
117117
g)
118118
github_token_location=$OPTARG
119-
;;
119+
;;
120120
c)
121121
cloudwatch_group=$OPTARG
122122
;;
@@ -281,7 +281,7 @@ elif [ "${action}" == "document" ]; then
281281
cloudwatch_group="aws-connect"
282282
fi
283283

284-
echo "Running ${document_name} on instance ${instance_id}"
284+
echo "Running ${document_name} on instance ${instance_id}"
285285

286286
# create the send-command as a string so that parameters can be appended on if needed
287287
aws_command="aws ssm send-command \
@@ -305,11 +305,11 @@ elif [ "${action}" == "document" ]; then
305305

306306
if [ "$?" != "0" ]; then
307307
echo "Unable to execute command!"
308-
exit 0
308+
exit 1
309309
fi
310310

311311
echo "Command ID: $sh_command_id"
312-
312+
313313
# get the status of the command
314314
status=$(aws ssm list-command-invocations \
315315
--command-id "${sh_command_id}" \
@@ -336,21 +336,13 @@ elif [ "${action}" == "document" ]; then
336336

337337
echo "Command still running..."
338338
sleep 5
339-
339+
340340
status=$(aws ssm list-command-invocations \
341341
--command-id "${sh_command_id}" \
342342
--details \
343343
--output text \
344344
--no-paginate \
345-
--query "CommandInvocations[0].Status")
346-
347-
# check if the command has failed
348-
for (( i = 0; i < "${#ssm_failed_statuses[@]}"; i++ )); do
349-
if [ "${ssm_failed_statuses[$i]}" == "${status}" ]; then
350-
echo "Failure Status: ${ssm_failed_statuses[$i]}!"
351-
endLoop="true"
352-
fi
353-
done
345+
--query "CommandInvocations[0].Status")
354346

355347
# check if the command has succeeded. If so then get the command output
356348
if [ "Success" == "${status}" ]; then
@@ -370,6 +362,15 @@ elif [ "${action}" == "document" ]; then
370362
endLoop="true"
371363
fi
372364

365+
# check if the command has failed
366+
for (( i = 0; i < "${#ssm_failed_statuses[@]}"; i++ )); do
367+
if [ "${ssm_failed_statuses[$i]}" == "${status}" ]; then
368+
echo "Failure Status: ${ssm_failed_statuses[$i]}!"
369+
endLoop="true"
370+
exit 1
371+
fi
372+
done
373+
373374
done
374375

375376
else

0 commit comments

Comments
 (0)