GitHub Actions environment variables: set env, defaults and vars
Every default GitHub Actions environment variable, how to set env at workflow, job and step level, GITHUB_ENV, GITHUB_PATH and vars.
In this series24 guides, you're on Environment variables
GitHub Actions gives you three kinds of variables:
- Default environment variables that GitHub sets on every runner (
GITHUB_SHA,GITHUB_REF,RUNNER_OS…). - Custom environment variables you set with
env:in the workflow, or from a step through$GITHUB_ENV. - Configuration variables (
vars) stored in the repository, organization or environment settings, for non-secret values such as a region or an account ID.
Default environment variables#
These are set for every step. Most have a matching github context property (GITHUB_SHA is ${{ github.sha }}): use the variable inside run: scripts and the context in YAML fields such as if: or with:. Default variables are not in the env context: ${{ env.GITHUB_SHA }} is empty, so use ${{ github.sha }}.
Some values exist only as a context, with no variable. job.check_run_id holds the current job’s check run ID, for example to fetch the job’s check run through the REST API. To use it in a script, map it in the step’s env:, as in CHECK_RUN_ID: ${{ job.check_run_id }}. As of November 2026, GitHub Enterprise Server doesn’t have it.
The run and the event#
| Variable | What it holds | Example |
|---|---|---|
CI | Always true. | true |
GITHUB_ACTIONS | Always true when running in GitHub Actions. | true |
GITHUB_EVENT_NAME | The event that triggered the run. | pull_request |
GITHUB_EVENT_PATH | Path to a JSON file with the full webhook payload. | /home/runner/work/_temp/_github_workflow/event.json |
GITHUB_WORKFLOW | The workflow’s name, or its file path if it has none. | CI |
GITHUB_WORKFLOW_REF | The workflow file’s path and ref. | my-org/my-repo/.github/workflows/ci.yml@refs/heads/main |
GITHUB_WORKFLOW_SHA | The commit the workflow file was read from. | ffac537e… |
GITHUB_RUN_ID | A unique ID for the run, the same across re-runs. | 1658821493 |
GITHUB_RUN_NUMBER | The run’s number for this workflow, starting at 1. | 42 |
GITHUB_RUN_ATTEMPT | Which attempt of the run this is, starting at 1. | 2 |
GITHUB_JOB | The current job’s ID. | test |
GITHUB_ACTION | The current step’s id, or a generated name. | __run_2 |
GITHUB_ACTOR | Who triggered the run. | octocat |
GITHUB_ACTOR_ID | Their account ID. | 1234567 |
GITHUB_TRIGGERING_ACTOR | Who triggered this attempt (differs from GITHUB_ACTOR on a re-run by someone else). | hubot |
GITHUB_RETENTION_DAYS | How many days logs and uploaded artifacts are kept. | 90 |
The repository and the commit#
| Variable | What it holds | Example |
|---|---|---|
GITHUB_REPOSITORY | Owner and repository name. | octocat/hello-world |
GITHUB_REPOSITORY_ID | The repository’s ID. | 123456789 |
GITHUB_REPOSITORY_OWNER | The owner’s name. | octocat |
GITHUB_REPOSITORY_OWNER_ID | The owner’s ID. | 1234567 |
GITHUB_SHA | The commit that triggered the run. For pull_request, the merge commit. | ffac537e6cbbf934b08745a378932722df287a53 |
GITHUB_REF | The full ref that triggered the run. | refs/heads/main, refs/pull/42/merge, refs/tags/v1.2.0 |
GITHUB_REF_NAME | The short ref name. | main, 42/merge, v1.2.0 |
GITHUB_REF_TYPE | branch or tag. | branch |
GITHUB_REF_PROTECTED | true if branch protection or rulesets apply to the ref. | false |
GITHUB_HEAD_REF | The PR’s source branch (pull_request and pull_request_target only). | feature-login |
GITHUB_BASE_REF | The PR’s target branch (pull_request and pull_request_target only). | main |
GITHUB_SERVER_URL | The GitHub server’s URL. | https://github.com |
GITHUB_API_URL | The REST API URL. | https://api.github.com |
GITHUB_GRAPHQL_URL | The GraphQL API URL. | https://api.github.com/graphql |
The runner and its files#
| Variable | What it holds | Example |
|---|---|---|
GITHUB_WORKSPACE | The default working directory, where actions/checkout puts the code. | /home/runner/work/my-repo/my-repo |
RUNNER_OS | Linux, Windows or macOS. | Linux |
RUNNER_ARCH | X86, X64, ARM or ARM64. | X64 |
RUNNER_NAME | The runner’s name. | GitHub Actions 12 |
RUNNER_ENVIRONMENT | github-hosted or self-hosted. | github-hosted |
RUNNER_TEMP | A temporary directory, emptied at the start and end of every job. | /home/runner/work/_temp |
RUNNER_TOOL_CACHE | Where preinstalled tool versions live (used by setup-* actions). | /opt/hostedtoolcache |
RUNNER_DEBUG | 1 when debug logging is on. | 1 |
GITHUB_ENV | File that sets environment variables for the next steps. | /home/runner/work/_temp/_runner_file_commands/set_env_… |
GITHUB_OUTPUT | File that sets the current step’s outputs. | …/set_output_… |
GITHUB_PATH | File that prepends directories to PATH for the next steps. | …/add_path_… |
GITHUB_STEP_SUMMARY | File whose Markdown is shown on the run’s summary page. | …/step_summary_… |
GITHUB_ARTIFACTS | File that declares files or OCI image digests as the step’s workflow artifacts ↗, one per line. The runner records each name and digest; nothing is uploaded. | …/artifacts_… |
GITHUB_ARTIFACTS_LIST | Read-only JSON file listing the artifacts declared by earlier steps of the job. | …/artifacts_list_… |
GITHUB_ACTION_PATH | The action’s directory (composite actions only). | /home/runner/work/_actions/my-org/my-action/v1 |
GITHUB_ACTION_REPOSITORY | The action’s repository, for steps that use one. | actions/checkout |
GITHUB_TOKEN is not a default environment variable. It’s a secret: pass it in explicitly with env: GH_TOKEN: ${{ github.token }} (or secrets.GITHUB_TOKEN). GitHub’s variables reference ↗ has the full list, and you can’t override a GITHUB_* or RUNNER_* variable: GitHub sets them last.
To see them all on a runner, add a step that runs env | sort. It also shows GITHUB_STATE, a file that actions write to share values with their pre: and post: steps; run: steps don’t need it. To dump the contexts as JSON instead, see Print the contexts in the debugging guide.
Setting your own variables with env#
env: works at three levels, and the most specific one wins:
name: Build
on: push
env: NODE_ENV: production # every job and step
jobs: build: runs-on: ubuntu-latest env: LOG_LEVEL: debug # every step of this job steps: - name: Uses all three env: TARGET: web # this step only run: echo "$NODE_ENV $LOG_LEVEL $TARGET"
- name: Step-level wins over job-level env: LOG_LEVEL: warn run: echo "$LOG_LEVEL" # warnValues can be expressions, for example ARTIFACT: build-${{ github.run_number }}-${{ github.sha }}. Each level allows only some contexts: github, vars, secrets and inputs everywhere, plus needs, strategy and matrix in a job’s env. Only a step’s env can read env, runner, job or steps, so ${{ env.REGISTRY }} inside another workflow-level variable, or ${{ runner.temp }} in a job’s env, fails. Build those in the step’s env or in the shell.
env doesn’t cross into a reusable workflow: the called workflow doesn’t see the caller’s env, and the caller doesn’t see the called workflow’s. Pass values as inputs and outputs, or use vars, which come from the caller’s repository. Inside a reusable workflow, GITHUB_WORKFLOW, GITHUB_WORKFLOW_REF and GITHUB_WORKFLOW_SHA describe the caller, because the github context is the caller’s. Four job context properties describe the called workflow’s own file instead: job.workflow_ref, job.workflow_sha, job.workflow_repository (owner/repo) and job.workflow_file_path. They have no environment variable. With repository: ${{ job.workflow_repository }} and ref: ${{ job.workflow_sha }}, actions/checkout checks out the reusable workflow’s own repository, at the commit the workflow was read from, instead of the caller’s. In a job defined directly in the workflow, job.workflow_ref is the same as github.workflow_ref. As of November 2026, GitHub Enterprise Server doesn’t have these properties.
env.X in YAML vs $X in the shell: inside run:, use the shell form ($X on Linux and macOS, $env:X in PowerShell). ${{ env.X }} is replaced in the script text before it runs, which breaks on quotes and newlines and opens the door to script injection with untrusted values.
Setting a variable from a step: $GITHUB_ENV#
A variable you export in one step is gone in the next, because each run: is a new shell. Append NAME=value to the file at $GITHUB_ENV instead, and it’s set for every following step of the same job:
steps: - uses: actions/checkout@v7 with: fetch-depth: 0 # history and tags, for git describe
- name: Compute the version run: echo "VERSION=$(git describe --tags --always)" >> "$GITHUB_ENV"
- name: Use it run: echo "Building $VERSION"Six things to know:
- The variable is not visible in the step that writes it, only in the next ones. Within that step, use a shell variable.
- Later steps also see it in expressions:
${{ env.VERSION }}works in theirif:andwith:. It replaces a workflow- or job-levelenvvalue of the same name, but a step’s ownenv:still wins. - It doesn’t cross to other jobs. Use job outputs for that.
- Variables and outputs from a step that runs with
background: truereach later steps only after awaitorwait-allthat includes it, and those from a step in aparallelgroup only once the whole group has finished (see parallel steps). NODE_OPTIONScan’t be set through$GITHUB_ENV: for security reasons, the runner skips it and logs an error. Set it withenv:instead, for exampleNODE_OPTIONS: --max-old-space-size=4096.- Multi-line values need a delimiter:
- run: | { echo "CHANGELOG<<EOF" git log --oneline -5 echo "EOF" } >> "$GITHUB_ENV"Every later step prints the variable and its value at the start of its log. If the value is sensitive, such as a token you generate, mask it with the add-mask workflow command before you write it anywhere, so the logs show *** in its place:
- run: | TOKEN="$(./generate-token.sh)" echo "::add-mask::$TOKEN" echo "TOKEN=$TOKEN" >> "$GITHUB_ENV"Values from secrets are masked already: add-mask is for values you compute during the run.
$GITHUB_ENV sets environment variables for every later step. $GITHUB_OUTPUT sets a named output of the step, read as steps.<id>.outputs.<name>, which is also how you feed job outputs (see $GITHUB_ENV or $GITHUB_OUTPUT).
To add a directory to PATH for the next steps, append it to $GITHUB_PATH: echo "$HOME/.local/bin" >> "$GITHUB_PATH".
Configuration variables: vars#
For values you don’t want hard-coded in the workflow but that aren’t secret, create variables under Settings → Secrets and variables → Actions → Variables for a repository or an organization. For an environment, open Settings → Environments, click the environment, then Add variable under Environment variables. Read them with the vars context:
jobs: deploy: runs-on: ubuntu-latest environment: production env: AWS_REGION: ${{ vars.AWS_REGION }} steps: - run: echo "Deploying to $AWS_REGION"They are not exported as environment variables on their own: map them with env: as above. When the same name exists at several levels, the environment’s value wins over the repository’s, which wins over the organization’s. Unlike secrets, vars are shown in logs and can be used in if: conditions.
On GitHub Free, private repositories can’t read organization-level variables or configure environments, so they get no environment-level variables either. A private repository needs GitHub Pro, Team or Enterprise for environments, and an organization on Team or Enterprise for organization variables.
Choosing the right one#
| You need… | Use |
|---|---|
| A fixed value in the workflow | env: at the workflow, job or step level |
| A value computed in one step, for later steps of the same job | $GITHUB_ENV |
| A named value from one step, for later steps of the same job | Step output: $GITHUB_OUTPUT, read as steps.<id>.outputs.<name> |
| A value computed in one job, for another job | Job outputs and needs |
| A per-environment or per-repository setting | vars |
| A password, token or key | secrets (masked in logs) |
| Information about the run (commit, branch, actor) | The default GITHUB_* variables |
Practical example: per-branch configuration#
name: Deploy
on: push: branches: [main, staging]
jobs: deploy: runs-on: ubuntu-latest environment: ${{ case(github.ref_name == 'main', 'production', 'staging') }} env: API_URL: ${{ vars.API_URL }} # set per environment in the settings steps: - uses: actions/checkout@v7 - run: ./deploy.sh "$API_URL"The case() ↗ function, added in January 2026, picks production on main and staging otherwise, and the job deploys to that environment, which supplies its own API_URL variable and secrets. The older form, ${{ github.ref_name == 'main' && 'production' || 'staging' }}, does the same. Use it on GitHub Enterprise Server, whose docs don’t list case(), and with act, which rejects case() as of November 2026. A separate job that decides and passes the name as a job output only pays off when the decision needs a script, such as reading a file or calling an API.
On RunsOn#
On RunsOn runners, RUNNER_ENVIRONMENT is self-hosted, and since v3.5.0 (October 2026) the Linux paths, such as GITHUB_WORKSPACE and RUNNER_TEMP, match GitHub-hosted runners. Every job also gets RUNS_ON_* variables, such as RUNS_ON_INSTANCE_TYPE, RUNS_ON_INSTANCE_LIFECYCLE (spot or on-demand) and RUNS_ON_AWS_REGION:
- run: echo "$RUNS_ON_INSTANCE_TYPE ($RUNS_ON_INSTANCE_LIFECYCLE) in $RUNS_ON_AWS_REGION"