Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Github Workflows: Changing or specifying environment variables in matrix jobs

How do I specify or change an environment variable as part of a job matrix?

For example, here I want my job to echo "Two" and "Three" instead of "One", but github completely ignores the definition or change of the environment variable in the matrix:

name: test-test-test

on:
  push:
    branches: [ main, develop ]
  pull_request:
    branches: [ main, develop ]

env:
  MY_VAR: One

jobs:
  test:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        include:
          - env:
              MY_VAR: Two
          - env:
              MY_VAR: Three
    steps:
      - run: echo "$MY_VAR2"

yields echo "One" and echo "One" in both jobs.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Use this context to access information about environment variables that have been set in a workflow, step, or job. Note that you cannot use the env context in the value of the id and uses keys within a step. An example is env.env_var.

GitHub provides extensive documentation about contexts at
https://docs.github.com/en/actions/learn-github-actions/contexts.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading