diff --git a/.github/actions/ssm-send-command/action.yml b/.github/actions/ssm-send-command/action.yml index d38c0eec..330d8531 100644 --- a/.github/actions/ssm-send-command/action.yml +++ b/.github/actions/ssm-send-command/action.yml @@ -24,6 +24,35 @@ runs: --query "Command.CommandId") echo "command-id=$COMMAND_ID" >> $GITHUB_OUTPUT + - name: Check stop services command status and retrieve output + shell: bash + run: | + while true; do + STATUS=$(aws ssm list-command-invocations \ + --command-id ${{ steps.run-command.outputs.command-id }} \ + --details \ + --query "CommandInvocations[0].Status" \ + --output text) + echo "Command Status: $STATUS" + + OUTPUT=$(aws ssm list-command-invocations \ + --command-id ${{ steps.run-command.outputs.command-id }} \ + --details \ + --query "CommandInvocations[0].CommandPlugins[0].Output" \ + --output text) + echo "Command Output: $OUTPUT" + + if [ "$STATUS" == "Success" ]; then + echo "Command completed successfully." + break + elif [ "$STATUS" == "Failed" ] || [ "$STATUS" == "Cancelled" ]; then + echo "Command failed with status: $STATUS" + exit 1 + else + sleep 10 # Wait for 30 seconds before checking again + fi + done + - name: Wait for command completion shell: bash id: poll-status @@ -37,6 +66,8 @@ runs: --query "CommandInvocations[0].Status" \ --output text) + echo "status is $STATUS" + # Print a progress `.` token until the command completes. case $STATUS in Pending | InProgress | Delayed )