Two-Dimension Matrix

JFrog Pipelines Documentation

Products
JFrog Pipelines
Content Type
User Guide
ft:sourceType
Paligo

A Matrix step can also perform the same operations in multiple runtime environments. For example, running tests in Java and Javascript, or in different release versions of the same runtime.

This can be done as a single-dimension matrix (performing a single, fixed set of actions in each runtime) or as a two-dimension matrix (performing different actions with different configurations in multiple runtimes).

If we modify the single matrix example above to run in both Java and Javascript runtimes, it will execute in a total of 6 steplets; in 2 runtimes for each of 3 sets of environment variables:

Runtime

Set 1

Set 2

Set 3

java 13.0

dog, copper, carrot

goat, iron, broccoli

lizard, lead, <null>

node 8.17.0

dog, copper, carrot

goat, iron, broccoli

lizard, lead, <null>

For more information, see the Matrix Pipeline Example.

Matrix Pipeline Example

The following example pipeline can be found in the JFrog GitHub repository. You can fork this repo to your own GitHub account to try on your own installation of Pipelines.

The two-dimension matrix pipeline provides a simplified example of running tests in modules in different runtime environments. It performs basic functionality tests on four different math operation modules, repeating these tests in different release versions of nodejs.

Resources

The first step of the pipeline will trigger on any change to the example GitHub repo, which also houses the test files. So any change to the tests or the pipeline will trigger a new run of the pipeline.

If you have forked the example, you will need to change the path and integration name as noted in the comments.

resources:
  - name: sample_code
    type: GitRepo
    configuration:
      path: jfrog/jfrog-pipelines-matrix-example      # Change to your own path
      branches:
        include: ^master$
      gitProvider: jfrog_github                       # Change to your own GitHub integration name

PreMatrix Step

The PreMatrix generic step is an optional step for performing preamble operations. It may be used to prepare a build environment for execution of a Matrix step.

Our example PreMatrix step loads the npm package dependencies that will be needed by the steplets.

PreMatrix Example Step

pipelines:
  - name: myPipeline
    steps:
      - name: setup
        type: PreMatrix
        configuration:
          inputResources:
            - name: sample_code
        execution:
          onExecute:
            - echo "Preparing the code base"
            - pushd "${res_sample_code_resourcePath}/app"
            - npm install
            - popd 
            - mkdir -p app
            - cp -r "${res_sample_code_resourcePath}/app/." ./app/

Matrix Step

The Matrix step executes the test cases for each module in multiple versions of the nodejs runtime. The modules are specified as environment variables in stepletMultipliers , which also specifies the runtimes.

Matrix Example Step

      - name: test
        type: Matrix
        stepMode: Bash
        configuration:
          inputSteps:
            - name: setup
        stepletMultipliers:
          environmentVariables:
            - module: mod_1
            - module: mod_2
            - module: mod_3
            - module: mod_4
          runtimes:
            - type: image
              image:
                auto:
                  language: node
                  versions:
                    - 12
            - type: image
              image:
                auto:
                  language: node
                  versions:
                    - 8.17.0                    
        execution:
          onExecute:
            - pushd ./setup/app
            - MODULE="$module" npm run test
            - popd
          onComplete:
            - save_tests ./setup/app/reports

PostMatrix Step

The PostMatrix generic step is an optional step for performing post-execution tasks following a Matrix step.

In the example pipeline, the PostMatrix step aggregates all the test reports.

PostMatrix Step Example

      - name: output
        type: PostMatrix
        configuration:
          inputSteps: 
            - name: test
        execution:
          onExecute:
            - echo "Executing the output step"
            - ls -ltr ./test/setup/app/reports
            - save_tests ./test/setup/app/reports

When the example pipeline is loaded and run, the Matrix step executes eight steplets. The run log for each steplet, including saved test results, can be viewed from the pipeline's run history.

image2020-7-16_14-51-12.png

The run log of the PostMatrix step shows the aggregated results of all steplets.

image2020-7-16_14-55-51.png