Skip to content

[GitHub Actions (new)] [BUG] Unable to create environment variables based matrix #27139

[GitHub Actions (new)] [BUG] Unable to create environment variables based matrix #27139
Aug 15, 2019 · 8 answers

Here’s what I’m trying:

jobs:
  build:
runs-on: ubuntu-latest
strategy:
  max-parallel: 4
  matrix:
    python-version:
    - 3.7
    os:
    - ubuntu-18.04
    env:
    - TOXENV: python,check-docs,build-docs
  • TOXENV: build-dists,pre-commit-ci

I want to generate a number of jobs from matrix also taking into account the specified env vars. Just like Travis CI does:

Anything I’m missing?

Workaround is to explicitly apply the env factor on a job level:

jobs:
  build:
runs-on: ubuntu-latest
strategy:
  max-parallel: 4
  matrix:
    python-version:
    - 3.7
    os:
    - ubuntu-18.04
    env:
    - TOXENV: python,check-docs,build-docs
  • TOXENV: build-dists,pre-commit-ci
    steps:
  • ...
  • run: |
    some-command --with-access-to=env
    env: ${{matrix.env }}

Replies

8 suggested answers

Hi @webknjaz, thanks for being here! Did you give this workflow a go? Are you having any problems?

0 replies

Hi @andreagriffiths11, I tried it and it doesn’t create jobs with different env var values from the matrix.

0 replies

Workaround is to explicitly apply the env factor on a job level:

jobs:
  build:
runs-on: ubuntu-latest
strategy:
  max-parallel: 4
  matrix:
    python-version:
    - 3.7
    os:
    - ubuntu-18.04
    env:
    - TOXENV: python,check-docs,build-docs
  • TOXENV: build-dists,pre-commit-ci
    steps:
  • ...
  • run: |
    some-command --with-access-to=env
    env: ${{matrix.env }}
0 replies
Answer selected

@webknjaz, what about this mechanism ? https://docs.travis-ci.com/user/environment-variables/#defining-multiple-variables-per-item

0 replies

That’s essentially the same except that with GH Actions you have to expose vars to each job explicitly.

0 replies

I just checked and it turns out that you can use env: on the job level too now: https://help.github.com/en/actions/automating-your-workflow-with-github-actions/workflow-syntax-for-github-actions#jobsjob_idenv

0 replies

@webknjaz Could you provide an example as i have tried and failed as actions does not support multiple env variables.

I would like each job to receive multiple variables like

FOO=bar BAR=foo
0 replies

@webknjaz Sorry figured it out:

  • {FOO: bar, BAR=foo}

The actions editor on github tripped me up with the error “only primitive types are allowed for”.

0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants