2022-05-30 23:12:18 +00:00
# Matrix pipelines
2019-11-15 11:03:15 +00:00
2022-05-30 23:12:18 +00:00
Woodpecker has integrated support for matrix pipeline. Woodpecker executes a separate pipeline for each combination in the matrix, allowing you to build and test a single commit against multiple configurations.
2019-11-15 11:03:15 +00:00
Example matrix definition:
```yaml
matrix:
GO_VERSION:
- 1.4
- 1.3
REDIS_VERSION:
- 2.6
- 2.8
- 3.0
```
Example matrix definition containing only specific combinations:
```yaml
matrix:
include:
- GO_VERSION: 1.4
REDIS_VERSION: 2.8
- GO_VERSION: 1.5
REDIS_VERSION: 2.8
- GO_VERSION: 1.6
REDIS_VERSION: 3.0
```
## Interpolation
2022-10-14 14:57:45 +00:00
Matrix variables are interpolated in the YAML using the `${VARIABLE}` syntax, before the YAML is parsed. This is an example YAML file before interpolating matrix parameters:
2019-11-15 11:03:15 +00:00
```yaml
2022-05-30 23:12:18 +00:00
matrix:
GO_VERSION:
- 1.4
- 1.3
DATABASE:
- mysql:5.5
- mysql:6.5
- mariadb:10.1
2019-11-15 11:03:15 +00:00
pipeline:
build:
image: golang:${GO_VERSION}
commands:
- go get
- go build
- go test
services:
database:
image: ${DATABASE}
```
2022-05-19 18:07:27 +00:00
Example YAML file after injecting the matrix parameters:
2019-11-15 11:03:15 +00:00
```diff
pipeline:
build:
2021-11-20 19:45:59 +00:00
- image: golang:${GO_VERSION}
+ image: golang:1.4
2019-11-15 11:03:15 +00:00
commands:
- go get
- go build
- go test
+ environment:
+ - GO_VERSION=1.4
+ - DATABASE=mysql:5.5
services:
database:
2021-11-20 19:45:59 +00:00
- image: ${DATABASE}
+ image: mysql:5.5
2019-11-15 11:03:15 +00:00
```
## Examples
2022-05-30 23:12:18 +00:00
### Example matrix pipeline based on Docker image tag
2019-11-15 11:03:15 +00:00
```yaml
2022-05-30 23:12:18 +00:00
matrix:
TAG:
- 1.7
- 1.8
- latest
2019-11-15 11:03:15 +00:00
pipeline:
build:
image: golang:${TAG}
commands:
- go build
- go test
```
2022-05-30 23:12:18 +00:00
### Example matrix pipeline based on container image
2019-11-15 11:03:15 +00:00
```yaml
2022-05-30 23:12:18 +00:00
matrix:
IMAGE:
- golang:1.7
- golang:1.8
- golang:latest
2019-11-15 11:03:15 +00:00
pipeline:
build:
image: ${IMAGE}
commands:
- go build
- go test
2022-05-30 23:12:18 +00:00
```
2019-11-15 11:03:15 +00:00
2022-05-30 23:12:18 +00:00
### Example matrix pipeline using multiple platforms
```yaml
2019-11-15 11:03:15 +00:00
matrix:
2022-05-30 23:12:18 +00:00
platform:
- linux/amd64
- linux/arm64
platform: ${platform}
pipeline:
test:
image: alpine
commands:
- echo "I am running on ${platform}"
test-arm-only:
image: alpine
commands:
- echo "I am running on ${platform}"
- echo "Arm is cool!"
when:
platform: linux/arm*
2019-11-15 11:03:15 +00:00
```