The Matrix step is useful for performing the same operation multiple times, but with different settings each time. This could mean pushing the same Docker image to different registries, or executing the same set of unit tests with different test values.
For example, we might want to perform the same test on a completed build with different sets of values for animal, mineral, and vegetable.
animal | mineral | vegetable | |
|---|---|---|---|
Variation 1 | dog | copper | carrot |
Variation 2 | goat | iron | broccoli |
Variation 3 | lizard | lead | <null> |
This example pipeline triggers on any change to the BuildInfo resource produced by another pipeline. The Matrix step performs the same execution actions in parallel steplets, with each using a different set of animal, mineral, and vegetable values from the collection specified in the stepletMultipliers:environmentVariables block.
pipelines:
- name: Matrix_Single_Pipeline
steps:
- name: matrix_example
type: Matrix
stepMode: Bash
configuration:
inputResources:
- name: CompletedBuildInfo
stepletMultipliers:
environmentVariables: # Sets of environment variables for steplets
- animal: dog # - Set 1
mineral: copper
vegetable: carrot
- animal: goat # - Set 2
mineral: iron
vegetable: broccoli
- animal: lizard # - Set 3
mineral: lead
execution:
onExecute:
- echo "Executing matrix step on ${steplet_id}"
- echo "Variation animal = ${animal}, mineral = ${mineral}, vegetable = ${vegetable}"When successfully executed, the run log of the pipeline shows the set of steplets executed by the Matrix step, along with their individual success status and the set of values used for the Matrix Combination.