GitHub Actions matrix strategy lets you run the same job across multiple environments—OS versions, language runtimes, or Docker images—without duplicating workflow steps. This approach maximizes parallelism, simplifies maintenance, and accelerates your CI/CD pipeline.Documentation Index
Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
Use this file to discover all available pages before exploring further.
Table of Contents
- A Straightforward Workflow
- Why Use a Matrix Strategy?
- Converting to a Matrix Workflow
- Handling Failures in a Matrix
- Further Reading
1. A Straightforward Workflow
Here’s a basic GitHub Actions workflow that runs two independent jobs—one on Ubuntu, one on Windows—to echo Docker info and launch thehello-world container:



hello-world output confirms success:
2. Why Use a Matrix Strategy?
Maintaining separate jobs for each OS, language version, or container image can quickly become repetitive and error-prone.| Challenge | Without Matrix Strategy | With Matrix Strategy |
|---|---|---|
| Duplication | Multiple job definitions | Single job with dynamic parameters |
| Maintenance | Manual updates across jobs | Update matrix values in one place |
| Parallelism | Limited by number of jobs defined | Instantly scales to all combinations |
Matrix strategy automatically runs all defined combinations in parallel, speeding up CI/CD feedback.
3. Converting to a Matrix Workflow
Let’s test two Docker images—hello-world and alpine—across three platforms: ubuntu-latest, ubuntu-20.04, and windows-latest. We’ll leverage the matrix variables in both runs-on and our Docker commands:


4. Handling Failures in a Matrix
By default, any failing combination halts the workflow and marks it as failed. For example,alpine isn’t compatible with Windows, so that job errors out:

A single matrix failure by default stops all running jobs. Use
strategy.fail-fast: false or exclude incompatible combinations with matrix.exclude.exclude and conditional execution.
5. Further Reading
- GitHub Actions: Matrix strategy
- Docker Hub – Alpine Official Image
- GitHub Actions Workflow syntax for GitHub Actions