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:
- ✓Go to the Actions tab
- ✓Click the workflow run
- ✓Scroll down to Artifacts section
- ✓Click to download as ZIP
Artifact vs Cache
| Cache | Artifact | |
|---|---|---|
| Purpose | Speed up builds (dependencies) | Store outputs (reports, builds) |
| Shared between | Runs (persists across runs) | Jobs (within one run) |
| Downloadable | No | Yes (from Actions UI) |
| Auto-deleted | After 7 days unused | After 90 days (configurable) |
