Maven / GitHub Actions Interview Questions
How do you share build artifacts between jobs using actions/upload-artifact and actions/download-artifact?
Because each job in a workflow runs on a separate, isolated runner, files created in one job are not visible to another job by default. actions/upload-artifact and actions/download-artifact bridge this gap by storing files in GitHub's artifact storage during the workflow run.
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build JAR
run: ./gradlew bootJar
- name: Upload JAR artifact
uses: actions/upload-artifact@v4
with:
name: app-jar # artifact name
path: build/libs/*.jar # what to upload
retention-days: 3 # auto-delete after 3 days
deploy:
runs-on: ubuntu-latest
needs: build
steps:
- name: Download JAR artifact
uses: actions/download-artifact@v4
with:
name: app-jar
path: dist/ # where to restore files
- name: Deploy
run: scp dist/*.jar user@server:/opt/app/
The name: field acts as the identifier that links upload to download. The downloading job must declare needs: build to ensure the artifact exists before it tries to fetch it.
Artifact vs cache: Artifacts are for passing build outputs (JARs, test reports, binaries) between jobs or making them available for download from the GitHub UI. Cache is for reusing dependency directories to speed up installs across workflow runs. Do not use one as a substitute for the other — they have different retention policies and semantics.
Artifacts uploaded with v4 default to a 90-day retention period unless overridden with retention-days:. Large artifacts (test videos, coverage HTML) should use short retention to avoid storage costs.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
