# Matrix parameters that reference each other

**URL:** <https://discuss.circleci.com/t/matrix-parameters-that-reference-each-other/42149>\
**Category:** Build Environment\
**Created:** [December 6, 2021, 5:35am UTC](https://discuss.circleci.com/t/matrix-parameters-that-reference-each-other/42149 "2021-12-06T05:35:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![magni](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/magni/32/25206_2.png) [@magni](https://discuss.circleci.com/u/magni)\
**Post date:** [December 6, 2021, 5:35am UTC](https://discuss.circleci.com/t/matrix-parameters-that-reference-each-other/42149/1 "2021-12-06T05:35:39Z")

</div>

I’m writing a matrix job definition for running integration tests against multiple platforms (`windows`, `mac`, `linux`). The integration tests are defined as individual commands (`test_foo`, `test_bar`, etc.):

```yaml
# jobs
integration_test:
  parameters:
    platform:
      # type: string rather than executor; otherwise the conditions used below won't work
      # See https://discuss.circleci.com/t/condition-on-executor-type/39711
      type: string
    test:
      type: steps
  executor: << parameters.platform >>
  steps:
    # various test setup steps omitted for brevity
    - steps: << parameters.test >>

# workflows.<workflow>.jobs
- integration_test:
    matrix:
      platform: [linux, mac, windows]
      test:
        - [test_foo]
        - [test_bar]

```

Unfortunately, my integration test commands take in a parameter to know whether they’re running on Windows or not\*. I’m passing in my integrations tests as `step` parameters, otherwise there is no way of running them; the following is invalid syntax:

```yaml
steps:
  # various test setup steps omitted for brevity
  - << parameters.test >>

```

If there’s a way to reference commands by name, I’m not finding it in the documentation. Something like:

```yaml
steps:
  # various test setup steps omitted for brevity
  - command: << parameters.test >>

```

The issue is that I can not alter passed in steps (to add the platform parameter). I can add parameters to the steps in the matrix definition, but those cannot reference the matrix parameters:

```yaml
# workflows.<workflow>.jobs
- integration_test:
    matrix:
      platform: [linux, mac, windows]
      test:
        - [test_foo: { platform: << parameters.platform >> }]
        - [test_bar: { platform: << parameters.platform >> }]

# Error: Error expanding: integration_test: matrix
# Arguments referenced without declared parameters: platform

```

\* I’m not finding a better way of getting this information. In GitHub actions, I’d use the runner context (` ${{ runner.os }}`), but I’m not finding an equivalent in CircleCI. I see there’s a [`circleci/os-detect` orb](https://circleci.com/developer/orbs/orb/circleci/os-detect), but it’s currently lacking Windows support… If I could get access to the platform info in my commands without needing to explicitly pass that in, then I wouldn’t have to pass in parameters in the first place.

---

<div class="post-metadata">

**Author:** ![magni](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/magni/32/25206_2.png) [@magni](https://discuss.circleci.com/u/magni)\
**Post date:** [December 6, 2021, 6:16am UTC](https://discuss.circleci.com/t/matrix-parameters-that-reference-each-other/42149/2 "2021-12-06T06:16:10Z")

</div>

My solution is to define two matrices:

```yaml
# workflows.<workflow>.jobs
- integration_test:
    matrix:
      platform: [linux, mac]
      test:
        - [test_foo]
        - [test_bar]
- integration_test:
    matrix:
      platform: [windows]
      test:
        - [test_foo: { windows: true }]
        - [test_bar: { windows: true }]

```

And this works! Now the only thing I’d like is a way to alias the `step` parameters so I could have `integration_test-windows-test_foo` rather than the current autogenerated `integration_test-windows-clojure.lang.LazySeq@752a7358`.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/circleci/original/3X/5/1/511608acda8e85906e15909b57bd0a46c1dbe291.png) [@system](https://discuss.circleci.com/u/system)\
**Post date:** [December 16, 2021, 6:16am UTC](https://discuss.circleci.com/t/matrix-parameters-that-reference-each-other/42149/3 "2021-12-16T06:16:18Z")

</div>

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