Maven / GitHub Actions Interview Questions
How do you use matrix builds in GitHub Actions to test across multiple environments?
A matrix strategy tells GitHub Actions to spawn multiple parallel job instances from a single job definition, varying one or more parameters across those instances. This is ideal for testing against several language versions, operating systems, or configuration combinations without duplicating YAML.
jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node: ['18', '20', '22']
fail-fast: false # continue other matrix jobs if one fails
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
- run: npm test
This definition spawns 3 × 3 = 9 parallel jobs, one for each OS/Node combination. Matrix values are referenced with ${{ matrix.<variable> }} anywhere in the job definition — including runs-on:, step inputs, and environment variables.
Key options:
fail-fast: false— by default, if any matrix job fails all remaining ones are cancelled. Set tofalseto let every combination finish regardless.include:— add extra combinations or inject extra variables into specific cells. For example, add a code-coverage flag only on Node 20/Ubuntu.exclude:— remove specific combinations from the matrix (e.g. skip macOS on an older Node version).max-parallel:— cap the number of concurrent jobs to avoid exhausting runner capacity.
Matrices can also be generated dynamically at runtime by having a prior job output a JSON array and referencing it with fromJSON(needs.setup.outputs.matrix).
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...
