Skip to content

Idea: Return the task log/output after task finishes if wait-for-finish set #2

Open
@cswilliams

Description

@cswilliams

First, thanks for all your updates to this action and your blog post, it was a big help to me! I'm not sure if this is the best place to talk about future ideas, but one idea I had was it would be really cool if the action could output the cloudwatch logs for the task when the task finishes. This is especially helpful if the task fails.

If anyone needs something like this today, I was able to implement this using another step like so. It will run even if the run-task step fails:

      - name: Fetch log output from run task
        if: always()
        run: |
          task_arn=${{ steps.run-task.outputs.task-arn }}
          if [ -n "$task_arn" ]; then
            #remove [] around task arn
            task_arn=`echo $task_arn | sed 's/[][]//g'`
            task_id=${task_arn##*/}
            aws logs get-log-events --log-group-name $LOG_GROUP_NAME --log-stream-name $LOG_PREFIX/$task_id --output text --start-from-head || exit 0
          else
            echo 'No logs available since run task did not run'
          fi

Perhaps another idea that would avoid cloudwatch logs altogether would be an action that can:

  1. Launch a task using run-task with --enable-execute-command and a container command like "sleep 3600"
  2. Wait until the task starts
  3. Run ECS's execute-command with the task id in step 1. I believe this should return the output from the command immediately to github actions. This does require the SSM Session Manager plugin though.
  4. Once execute-command completes, then stop the task.

I believe this way we could get the output of the command directly to github actions in real time as the command is running in the task. Unfortunately, there's no action I could find that can do ECS's execute-command yet, but hopefully some day. If I get some time, I may try this out with just aws cli commands. But for now, the step I posted above is working great to see logs from my task in Github actions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions