</>

Technology

GitHub Actions

Difficulty

Intermediate

Interview Question

What are GitHub Actions artifacts? How do you upload and download them?

Answer

GitHub Actions Artifacts

Artifacts let you persist files generated during a workflow — test reports, screenshots, build outputs, coverage reports — so you can download them after the workflow finishes.

Upload Artifacts

YAML
jobs:
  test:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4

      - name: Run tests
        run: mvn test
        continue-on-error: true    # don't stop if tests fail

      - name: Upload Surefire reports
        if: always()               # upload even if tests failed
        uses: actions/upload-artifact@v4
        with:
          name: surefire-reports
          path: target/surefire-reports/
          retention-days: 14       # keep for 14 days (default 90)

      - name: Upload Allure results
        if: always()
        uses: actions/upload-artifact@v4
        with:
          name: allure-results
          path: target/allure-results/

      - name: Upload screenshots on failure
        if: failure()
        uses: actions/upload-artifact@v4
        with:
          name: failure-screenshots-${{ github.run_number }}
          path: screenshots/

      - name: Upload built JAR
        uses: actions/upload-artifact@v4
        with:
          name: app-jar
          path: target/*.jar

Download Artifacts in Another Job

YAML
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: mvn clean package -DskipTests
      - uses: actions/upload-artifact@v4
        with:
          name: app-jar
          path: target/*.jar

  deploy:
    needs: build
    runs-on: ubuntu-latest
    steps:
      - name: Download built JAR
        uses: actions/download-artifact@v4
        with:
          name: app-jar
          path: ./artifacts/

      - name: Deploy
        run: |
          ls -la ./artifacts/
          ./deploy.sh ./artifacts/myapp-1.0.jar

Upload Multiple Paths

YAML
- uses: actions/upload-artifact@v4
  with:
    name: test-results
    path: |
      target/surefire-reports/
      target/extent-reports/
      screenshots/
      logs/*.log

Download All Artifacts From a Run

YAML
- name: Download all artifacts
  uses: actions/download-artifact@v4
  # No 'name' = downloads all artifacts into separate directories
  with:
    path: all-artifacts/

- run: ls -la all-artifacts/
# all-artifacts/
# ├── surefire-reports/
# ├── allure-results/
# └── app-jar/

Artifact Naming with Matrix

YAML
strategy:
  matrix:
    browser: [chrome, firefox]

steps:
  - name: Upload results
    if: always()
    uses: actions/upload-artifact@v4
    with:
      name: test-results-${{ matrix.browser }}   # unique name per matrix job
      path: target/surefire-reports/

View and Download Artifacts

After workflow runs:

  1. Go to the Actions tab
  2. Click the workflow run
  3. Scroll down to Artifacts section
  4. Click to download as ZIP

Artifact vs Cache

CacheArtifact
PurposeSpeed up builds (dependencies)Store outputs (reports, builds)
Shared betweenRuns (persists across runs)Jobs (within one run)
DownloadableNoYes (from Actions UI)
Auto-deletedAfter 7 days unusedAfter 90 days (configurable)

Follow AutomateQA

Related Topics