Define a list of elements in a variable #46785
-
Select Topic AreaQuestion BodyHi! 👋🏾 I'm trying to get an organization level workflow to get the list of Operating systems it should run from a variable, i.e.: Variable:
Workflow: ...
jobs:
test:
strategy:
matrix:
os: ${{ vars.TEST_OS_VERSIONS }}
... Unfortunately that does not work, trying it like the following either: Variable:
Workflow: ...
jobs:
test:
strategy:
matrix:
os: [ ${{ vars.TEST_OS_VERSIONS }} ]
... 😢 Any idea on how to use variables to to store a list of elements? For my projects and the organizations I participate in, being able to define on a global level the list of operating systems and python versions and override them on a per repository basis, would help us reduce, a lot, the workflows maintenance 🍀 🙏🏾 |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 10 replies
-
Hey @gforcada Did you try this way below? jobs:
test:
name: Testing on
runs-on:
- ubuntu-latest
- macos-latest
- windows-latest
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.11", "3.10", 3.9, 3.8, 3.7, pypy-3.9]
steps:
... |
Beta Was this translation helpful? Give feedback.
-
You can use fromJSON to parse your variable (json array) into an Array object for the matrix. ...
jobs:
test:
strategy:
matrix:
os: ${{ fromJSON(vars.TEST_OS_VERSIONS) }}
... You may run into issues with |
Beta Was this translation helpful? Give feedback.
You can use fromJSON to parse your variable (json array) into an Array object for the matrix.
You may run into issues with
pull_request
workflows, becausevars.TEST_OS_VERSIONS
might currently end up undefined.