Static environment variables in GitHub Actions
GitHub Actions environment variables have distinct scopes:
- Workflow
- Job
- Step
It’s trivial to set static environment variables in each of these scopes. Dynamically setting environment variables is also possible.
Workflow
Set static workflow environment variables in GitHub Actions by using env:
at the top level of a “.github/workflows/ci.yml” file like:
name: ci
env:
CTEST_PARALLEL_LEVEL: 0
CMAKE_BUILD_PARALLEL_LEVEL: 4
CTEST_NO_TESTS_ACTION: error
CMAKE_GENERATOR: Ninja
CC: gcc
Job
Static job environment variables are set like:
jobs:
base:
runs-on: macos-latest
strategy:
matrix:
cc: [gcc-13, clang]
env:
CMAKE_GENERATOR: Ninja
CC: ${{ matrix.cc }}
Step
Set static step environment variables like:
- run: cmake -B build
env:
CMAKE_GENERATOR: Ninja