1
votes

I am creating a /.github/<workflow>.yml and am struggling with the environment.

from https://help.github.com/en/actions/automating-your-workflow-with-github-actions/workflow-syntax-for-github-actions#env

A map of environment variables that are available to all jobs and steps in the workflow. You can also set environment variables that are only available to a job or step. For more information, see jobs.<job_id>.env and jobs.<job_id>.steps.env.

When more than one environment variable is defined with the same name, GitHub uses the most specific environment variable. For example, an environment variable defined in a step will override job and workflow variables with the same name, while the step executes. A variable defined for a job will override a workflow variable with the same name, while the job executes.

From https://help.github.com/en/actions/automating-your-workflow-with-github-actions/using-environment-variables

To set custom environment variables, you need to specify the variables in the workflow file. You can define environment variables for a step, job, or entire workflow using the jobs.<job_id>.steps.env, jobs.<job_id>.env, and env keywords. For more information, see "Workflow syntax for GitHub."

How do I set up environment variables for the entire workflow (multiple jobs)?

2
What you've posted seems to include that answer, could you clarify the issue with a minimal reproducible example? - jonrsharpe
the documented way of accomplishing this do not work... if I use the env-keyword in a context which is not a job or a step, GitHub is telling me that it is an invalid yml-file... - jactor-rises
Again, give a MRE; edit the question to include the relevant information. - jonrsharpe

2 Answers

0
votes

How do I set up environment variables for the entire workflow (multiple jobs)?

Well, you can't with the keyword env if you want to setup the environnement once. Ontherwise, you set the env in each job, like that :

jobs:
 build:
  runs-on: ubuntu-18.04
  env: 
   - FOO: foo
   - BAR: bar

  steps:
   - uses: actions/checkout@v1
   - name: Do something

 test:
  runs-on: ubuntu-18.04
  env: 
   - FOO: foo
   - BAR: bar

  steps:
   - uses: actions/checkout@v1
   - name: Do something else

But it depends if it's what you really want to do. A MRE would be appreciate, if it's not what you need, as jonrsharpe said.

0
votes
on: push

env:
 MY_ENV: value

jobs:

 job1:
  runs-on: ubuntu-latest
  steps:
  - run: echo "MY_ENV_1 = $MY_ENV"

 job2:
  runs-on: ubuntu-latest
  steps:
  - run: echo "MY_ENV_2 = $MY_ENV"

I'm 100% sure this one works, and 95% sure that you'll getting "invalid workflow" error due to mistake in other part of workflow or some minor syntax error (missing space, = instead of : when declaring variable, value starts with non-alphanumeric character and it's not inside '', etc).

Error report page is currently broken (at least for me) - whole message is in single line with no way to see more than just a beginning. If that's a case for you as well, use 'inspect element' in you browser, so you can see it in all its glory.