Can't make use of workflow environment variable in github action from marketplace (through build matrix)

Viewed 714

I'm trying to make use of a workflow environment variable in a marketplace action, using a build matrix but it's not working for some reason.

I basically want to define the database versions just once to avoid repeating them in multiple place in my workflow.

Here's my workflow (minimal reproducible example):

name: dummy
on:
  pull_request:
env:
  MONGODB_3_6: 3.6.13
  MONGODB_4_0: 4.0.13

jobs:
  test:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        MONGODB: [$MONGODB_4_0, $MONGODB_3_6]
    steps:
    - uses: actions/checkout@v2
    - name: Start MongoDB
      uses: supercharge/mongodb-github-action@1.3.0
      with:
        mongodb-version: ${{ matrix.MONGODB }}

And it's failing with the error below, as if the MONGODB_4_0 wasn't defined. enter image description here

Interesting fact, without the strategy matrix, I'm able to make it work using the env context(doc):

- name: Start MongoDB
  uses: supercharge/mongodb-github-action@1.3.0
  with:
    mongodb-version: ${{ env.MONGODB_4_0 }}
1 Answers

UPDATED: according tests and comments, I think matrix can't take environment variables and/or dynamic values.

so the best way will be :

matrix:
  MONGODB: [3.6.13, 4.0.13]

As @max said you can use a variable for your workflow, so I guess your matrix should be wrong, maybe you can try like that :

MONGODB: [${{ env.MONGODB_4_0 }}, ${{ env.MONGODB_3_6 }}]

You have only one job (test) so you can define your env variables at the job level also. Variables will be accessible for all the job :

jobs:
  test:
    runs-on: ubuntu-latest
    env:
      MONGODB_3_6: 3.6.13
      MONGODB_4_0: 4.0.13

For further information : github doc

Related