Skip to content
Latchkey

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 in run:.

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

Run this faster and cheaper on Latchkey managed runners. Start free →