How to Reference a Variable With the vars Context in GitHub Actions
The vars context exposes non-secret configuration variables defined at the org, repo, or environment level.
Define a variable under the Variables tab at any scope, then read it with ${{ vars.NAME }}. Variables are not masked, so use them for config and keep credentials in secrets.
Steps
- Add a variable under Settings (org, repo, or environment Variables).
- Reference
${{ vars.NAME }}anywhere expressions are allowed. - Use it in
if:,env:,with:, or directly inrun:.
Workflow
.github/workflows/ci.yml
jobs:
build:
runs-on: ubuntu-latest
if: vars.DEPLOY_ENABLED == 'true'
steps:
- run: echo "Target host is ${{ vars.API_HOST }}"Gotchas
- Every variable value is a string; compare booleans as
== 'true'. - A variable referenced at a scope where it is undefined resolves to an empty string.
Related guides
How to Use Environment-Scoped Variables in GitHub ActionsDefine non-secret configuration per environment in GitHub Actions with environment variables read through the…
How to Set a Default Environment Variable for All Jobs in GitHub ActionsSet a workflow-level env block in GitHub Actions so a variable is available to every job and step, with job-l…