What is the syntax for matrix jobs with multiple parameters per job?

I need a matrix job that generates two jobs. One for arm64, one for arm32v7. There’s 4 parameters, and each parameter has two values (one for arm32, one for arm64.) This is the syntax I’ve been using on github actions:

matrix:
  parameters:
    - {image_tag: 'linux-arm64v8', dynarec: 'arm64', zip_arch: 'arm64', appimage_arch: 'aarch64'}
    - {image_tag: 'linux-arm32v7', dynarec: 'arm', zip_arch: 'armhf', appimage_arch: 'armhf'}

This doesn’t work on Circle though. What’s the needed syntax for this?

The following is not suitable, since it will generate 16 jobs instead of 2:

matrix:
  parameters:
    image_tag:     ['linux-arm64v8', 'linux-arm32v7']
    dynarec:       ['arm64', 'arm']
    zip_arch:      ['arm64', 'armhf']
    appimage_arch: ['aarch64', 'armhf']

OK, this doesn’t seem to be possible. As a workaround, instead of using a matrix, I’m manually calling the job two times with the required parameters:

workflows:
  build:
    jobs:
      - build-linux:
          name: build-linux-arm64v8
          image_tag: 'linux-arm64v8'
          dynarec: 'arm64'
          zip_arch: 'arm64'
          appimage_arch: 'aarch64'
      - build-linux:
          name: build-linux-arm32v7
          image_tag: 'linux-arm32v7'
          dynarec: 'arm'
          zip_arch: 'armhf'
          appimage_arch: 'armhf'
      - upload-linux:
          requires:
            - build-linux-arm64v8
            - build-linux-arm32v7

Seems to work. This doesn’t scale, but fortunately my needs are small :slight_smile:

What you are describing is more of an array or list type, rather than a matrix and past posts indicate that circleci does not offer that type of parameter.

Current workarounds are messy and so not worth worrying about for a small number of values. They would include csv or json based strings being passed to a shell script to process the info and then create a config.yml file dynamically than can then be called - all rather a lot of work compared to being able to directly process the original example you gave.

1 Like

Hi @RealNC ,

As you have discovered, CircleCI will create jobs for all combinations of the parameters you specify under a matrix.

You can specify an exclude key and specify pairs of parameters to exclude, but this will quickly get messy as you would have to exclude 14 combinations. As a reference, this is what it would look like to exclude only 2 combinations:

version: 2.1

jobs:
  build:
    parameters:
      image_tag:
        type: enum
        enum: ['linux-arm64v8', 'linux-arm32v7']
      dynarec:
        type: enum
        enum: ['arm64', 'arm']
      zip_arch:
        type: enum
        enum: ['arm64', 'armhf']
      appimage_arch:
        type: enum
        enum: ['aarch64', 'armhf']
    docker:
      - image: cimg/base:edge
    steps:
      - run: echo "<< parameters.image_tag >> - << parameters.dynarec >> - << parameters.zip_arch >> - << parameters.appimage_arch >>"

workflows:
  build:
    jobs:
      - build:
          matrix:
            parameters:
              image_tag: ['linux-arm64v8', 'linux-arm32v7']
              dynarec: ['arm64', 'arm']
              zip_arch: ['arm64', 'armhf']
              appimage_arch: ['aarch64', 'armhf']
            exclude:
              - image_tag: 'linux-arm64v8'
                dynarec: 'arm'
                zip_arch: 'armhf'
                appimage_arch: 'armhf'
              - image_tag: 'linux-arm32v7'
                dynarec: 'arm64'
                zip_arch: 'arm64'
                appimage_arch: 'aarch64'
              

Workarounds such as the ones @rit1010 mentioned are definitely possible, but in your case it would be easiest to specify the job twice, and pass in the specific parameter values.

Best Regards

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.