Skip to content

Latest commit

 

History

History
86 lines (72 loc) · 2.15 KB

using-matrix-jobs.adoc

File metadata and controls

86 lines (72 loc) · 2.15 KB
description contentTags document-type
A how to guide for using matrix jobs to simplify your CircleCI configuration.
platform
Cloud
Server v4.x
Server v3.x
How-to

Using matrix jobs

Matrix jobs provide a way to run a job multiple times with arguments. Arguments are supplied using parameters. There are many uses for this feature, including testing on multiple operating systems and against different language or library versions.

Use matrix jobs to run multiple OS tests

In the following example, the test job is run across a Linux Docker container, Linux VM, and macOS environments, using two different versions of Node.js. On each run of the test job, different parameters are passed to set both the OS and the Node.js version:

{% include snippets/docker-auth.adoc %}

version: 2.1

orbs:
  node: circleci/node@4.7

executors:
  docker: # Docker using the Base Convenience Image
    docker:
      - image: cimg/base:stable
  linux: # a Linux VM running Ubuntu 20.04
    machine:
      image: ubuntu-2004:202107-02
  macos: # macos executor running Xcode
    macos:
      xcode: 14.2.0

jobs:
  test:
    parameters:
      os:
        type: executor
      node-version:
        type: string
    executor: << parameters.os >>
    steps:
      - checkout
      - node/install:
          node-version: << parameters.node-version >>
          install-yarn: true

workflows:
  all-tests:
    jobs:
      - test:
          matrix:
            parameters:
              os: [docker, linux, macos]
              node-version: ["14.17.6", "16.9.0"]

List jobs that will run

The expanded version of this matrix runs the following list of jobs under the all-tests workflow:

    - test-14.17.6-docker
    - test-16.9.0-docker
    - test-14.17.6-linux
    - test-16.9.0-linux
    - test-14.17.6-macos
    - test-16.9.0-macos

Next steps

For full details of the matrix jobs specification, see the Configuration Reference.