Skip to content
Latchkey

How to Archive Workflow Logs as an Artifact in GitHub Actions

Tee command output to log files, then upload the logs directory with if: always() so failures keep it.

Redirect step output to files under a logs/ directory, then upload that directory with actions/upload-artifact gated on if: always().

Steps

  • Write command output to files under logs/.
  • Upload the logs/ directory as an artifact.
  • Gate the upload with if: always() so failures still keep logs.

Workflow

.github/workflows/ci.yml
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: |
          mkdir -p logs
          npm ci 2>&1 | tee logs/install.log
          npm test 2>&1 | tee logs/test.log
      - name: Archive logs
        if: always()
        uses: actions/upload-artifact@v4
        with:
          name: run-logs
          path: logs/
          retention-days: 14

Gotchas

  • Piping to tee can mask the exit code; set pipefail in the shell if the install or test status must propagate.
  • Do not log secrets to files, since artifacts are not masked the way live log output is.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →