GitLab CI Matrix Generator
Build, test, and deploy pipeline with a safe parallel matrix
-
1Enter data
Enter content, paste text or load a file from disk. -
2Click the button
The tool will immediately process your data in the browser. -
3Get the result
Copy the finished text or save the file to your device.
return "Result ready in 0.1s";
}
Advanced options
The .gitlab-ci.yml file defines the pipeline. The matrix creates one job per version, the cache is separated by branch and version, and deployment runs only on the default branch.
Rate this tool:
Related tools
Other tools you may find usefulGitLab CI matrix generator for multiple versions
This generator creates a .gitlab-ci.yml file with build, test, optional deployment, and parallel: matrix. A single job template can test a project on several PHP, Node.js, or Python versions. Values are emitted as quoted YAML strings, preventing a version from being interpreted as a number, Boolean value, or a new configuration node.
The tool provides a secure starting point rather than a repository-specific pipeline. Its jobs call ./scripts/build.sh, ./scripts/test.sh, and ./scripts/deploy.sh, which you must adapt before committing the file. For a simpler pipeline without a matrix, compare the result with the GitLab CI generator. You can also inspect the finished document with the YAML validator.
How parallel: matrix works
When the matrix is enabled, the generator defines an environment-specific variable: PHP_VERSION, NODE_VERSION, or PY_VERSION. GitLab expands the definition into one job execution for each value. The container image uses an explicit variable boundary such as php:${PHP_VERSION}-cli, so the image suffix cannot become part of the variable name. With the matrix disabled, the first entered version is inserted directly and no undefined matrix variable remains.
test:
stage: test
image: 'php:${PHP_VERSION}-cli'
parallel:
matrix:
- PHP_VERSION: ['8.2', '8.3']
script:
- ./scripts/test.sh
Stages and job consistency
The stages list controls execution order. The generator always creates build and test jobs, so both matching stages must be present and build must precede test. Enabling deployment also requires deploy after test. This check prevents a document that parses correctly but runs verification or deployment in the wrong order. Stage names use a restricted character set and bounded length.
Cache separated by branch and version
Sharing cached dependencies between incompatible runtimes can produce intermittent failures. The generated key therefore includes CI_COMMIT_REF_SLUG and the selected matrix version. The path follows the environment: vendor/ for PHP, node_modules/ for Node.js, and .cache/pip/ for Python. The pull-push policy lets a job download an existing cache and update it after completion.
Deployment on the default branch only
The deployment job uses rules to compare CI_COMMIT_BRANCH with CI_DEFAULT_BRANCH. This is safer than hard-coding main, because repositories may use another default branch. A branch rule does not replace protected environments, manual approvals, or secret protection. Keep credentials in protected and masked GitLab variables and never put them directly in YAML.
Generated file elements
| Element | Purpose | Safety control |
|---|---|---|
stages | Execution order | Validated names and required build/test/deploy entries |
image | Job container | Fixed registry family and validated version tag |
parallel: matrix | Multiple runtime versions | Up to 12 unique, quoted values |
cache | Dependency reuse | Key separated by branch and version |
rules | Deployment condition | Default branch only |
How to prepare the configuration
- Select PHP, Node.js, or Python and keep only the versions your project actually supports.
- Define stages; retain build and test, and add deploy only when the repository has a reviewed deployment script.
- Decide whether running the complete matrix on every branch is worth the runner time.
- Generate the YAML, copy it to the repository root, and adapt all script commands.
- Validate the YAML, use GitLab CI Lint, and run the pipeline on a test branch before merging.
Frequently asked questions
Will values such as 3.10 and 3.11 remain strings?
Yes. Every matrix version tag is enclosed in YAML single quotes, preventing the parser from converting it to a number or another scalar type.
What happens when I disable the matrix?
The build and test jobs use the first entered version directly, without a matrix variable. Other values are ignored, so put the project's reference version first.
Can I add a custom stage?
Yes, provided its name passes validation. Required stages must remain because generated jobs refer to build, test, and optionally deploy.
Is the cache shared by all versions?
No. Its key includes the runtime version and branch, reducing the risk that one matrix variant restores incompatible dependencies from another.
Is the generated deployment production-ready?
It is a skeleton. The default-branch rule helps, but you still need a protected environment, safe variables, a suitable runner, and a reviewed deployment script.