Common use cases for Matrix steps are:
- Splitting a large test suite into smaller units, and executing them in parallel to reduce total execution time.
- Testing against multiple values of environment variables or multiple runtime images.
- Testing against multiple base operating system versions.
The matrix configuration can specify:
- Multiple sets of environment variable definitions
- Multiple runtime images
- Multiple node pools
- Multiple operating systems
The Matrix step executes the specified shell scripts multiple times in parallel steplets, in each specified runtime for each set of environment variables on each specified platform. For example, if a Matrix step specifies 3 sets of environment variables and 2 runtime images, it will run a total of 6 steplets (3 times in runtime 1, 3 times in runtime 2). If the Matrix step also specifies 2 node pools, it will run 12 steplets.
A Matrix step can be optionally preceded by aPreMatrixstep to prepare the build node environment for the steplets, and aPostMatrixstep to aggregate information produced by the steplets.For more information, seeUsing the Matrix Step.
Matrix step is available for Linux nodes only.
Usage
管道:名称:<字符串>步骤:-名称:<字符串> type: Matrix stepMode: Bash configuration: #inherits from Bash; //www.si-fil.com/confluence/display/JFROG/Bash multiNode:# optional, only needed if steplets # need to execute on separate nodes execution: onStart: - echo "Preparing for work..." onExecute: # required - echo "Executing steplet $step_name" - echo "env1 = $env1" - echo "env2 = $env2" onSuccess: - echo "Job well done!" onFailure: - echo "uh oh, something went wrong" onComplete: #always - echo "Cleaning up some stuff" stepletMultipliers: # optional, only needed if user nodePools: # wants to execute step against - windows # multiple operating systems - ubuntu_18 - ubuntu_16 environmentVariables: # optional, only needed if user - env1: one # wants to execute step against env2: two # multiple values of env - env1: abc env2: xyz runtimes: # optional, only needed if user - type: image # wants to execute step against image: # multiple images auto: language: version: custom: image: auto: language: version: custom: fastFail: # default false. If specified, matrix # step fails when any steplet fails, # unless specified in allowFailures allowFailures: # optional, array of combinations - nodePool: # that are allowed to fail environmentVariables: env1: abc env2: xyz runtime: exclude: # optional, array of combinations - nodePool: # that are not executed environmentVariables: env1: one env2: two runtime:
Tags
name
Analphanumericstring (underscores are permitted) that identifies the step.
type
Must beMatrixfor this step type.
stepmode
Specifies the runtime OS mode. May be eitherBashorPowerShell. If not specified, defaults toBash.
configuration
Specifies all configuration selections for the step'sexecutionenvironment. This step inherits theBash/PowerShellstep configuration tags, including these pertinenttags:
Tag |
Description of usage |
Required/Optional |
|---|---|---|
inputStep |
May specify a PreMatrix preamble step. |
Optional |
In addition, these tags can be defined to support the step's native operation:
Tag |
Description of usage |
Required/Optional |
|---|---|---|
multiNode |
When true, steplets will be required to run on separate nodes.Default is false. For more information, seeMulti-node Matrix. |
Optional |
stepletMultipliers
In addition, these tags can be defined to support the step's native operation:
Tag |
Description of usage |
Required/Optional |
|---|---|---|
nodePools |
A collection of node pool names. Recognized only when If not defined, the step will be executed in the default node pool, or the node pool specified in the
Example
steps: - name: step_1 type: Matrix stepMode: Bash configuration: multiNode: true stepletMultipliers: environmentVariables: - foo: foo - bar: bar nodePools: - gcp - aws 确保nodepools that are defined in the YAML already exist in Pipelines. |
Optional |
environmentVariables |
A collection of sets of environment variable definitions. Each set of definitions will be used in an execution of a steplet in each of the defined If not defined, then a single steplet will execute for each of the defined |
Optional |
runtimes |
A collection of runtime definitions. The step will be executed in each defined runtime, on each of the specified If not defined, then each steplet will be executed in the default runtime, or the runtime specified in the |
Optional |
fastFail |
When set to Default is false. |
Optional |
allowFailures |
A collection that specifies the combinations of |
Optional |
exclude |
A collection that specifies the combinations ofnodepools,environmentVariables, andruntimesthat will not be executed. |
Optional |
execution
Declares collections of shell command sequences to perform for pre- and post-execution phases:
| Tag | Description of usage | Required/Optional |
|---|---|---|
onStart |
Commands to execute in advance ofonExecute |
Optional |
onExecute |
Main commands to execute for the step | Optional |
onSuccess |
Commands to execute on successful completion | Optional |
onFailure |
Commands to execute on failed completion | Optional |
onComplete |
Commands to execute on any completion | Optional |
Reserved Keywords
onExecute,onStart,onSuccess,onFailure, andonCompleteare reserved keywords. Using these keywords in any other context in your execution scripts can cause unexpected behavior.
Examples
Example 1
This is anexampleof how to use the Matrix step to perform a build activity.
- name: matrix_example type: Matrix stepMode: Bash configuration: inputSteps: - name: matrix_fan_out_example 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 nodePools: - gcp - aws runtimes: # Runtimes for steplets - type: image image: auto: language: java versions: - 13.0 - type: image image: auto: language: node versions: - 8.17.0 execution: onExecute: - echo "I am executing matrix steplet ${steplet_id}" - echo "Envs animal= $animal , mineral = $mineral , vegetable = $vegetable" - echo "Runtime image name: $step_image_name | Runtime image tag: $step_image_tag"
When run, the above example will execute in a total of 6 steplets: in 2 runtimes for each of 3 sets of environment variables:
| 运行时 | Set 1 | Set 2 | Set 3 |
|---|---|---|---|
| java 13.0 | dog, copper, carrrot | goat, iron, broccoli | lizard, lead, |
| node 8.17.0 | dog, copper, carrrot | goat, iron, broccoli | lizard, lead, |
Example 2 - allowFailures, Exclude, fastFail
pipelines: - name: S_Matrix_0052 steps: - name: S_Matrix_0052 type: Matrix stepMode: Bash stepletMultipliers: fastFail: true allowFailures: - environmentVariables: delay: 1 fail: 'true' nodePool: windows runtime: host - environmentVariables: delay: 1 fail: 'true' nodePool: ubuntu runtime: host exclude: - environmentVariables: delay: 1 fail: 'true' nodePool: windows runtime: host - environmentVariables: delay: 1 fail: 'true' nodePool: ubuntu runtime: host environmentVariables: - delay: 1 fail: 'true' - delay: 2 fail: 'false' - delay: 3 fail: 'false' - delay: 5 fail: 'false' execution: onStart: - sleep "$delay" onExecute: - echo "I am on matrix step" - | [ $fail == 'false' ] - ls -l .
