GH-200 · Question #54
In GitHub Actions, where should you declare custom environment variables so they are accessible across all jobs and steps in a single workflow run?
The correct answer is B. Set env in the workflow YAML. Declaring environment variables using the env: key at the top level of the workflow YAML file makes them available to all jobs and steps within that workflow run. This is the correct scope for workflow-wide variables. Repository variables (A) are stored in GitHub settings and…
Question
In GitHub Actions, where should you declare custom environment variables so they are accessible across all jobs and steps in a single workflow run?
Options
- ARepository variables
- BSet env in the workflow YAML
- CEnvironment secrets
- DRunner command line arguments
How the community answered
(19 responses)- B95% (18)
- D5% (1)
Explanation
Declaring environment variables using the env: key at the top level of the workflow YAML file makes them available to all jobs and steps within that workflow run. This is the correct scope for workflow-wide variables. Repository variables (A) are stored in GitHub settings and are available across multiple workflows but are not declared in the YAML. Environment secrets (C) are scoped to deployment environments. Runner command line arguments (D) are not a supported mechanism for setting reusable environment variables across steps.
Topics
Community Discussion
No community discussion yet for this question.