Course contentsShow
← Cloud and Infrastructure
Lesson 1692 of 2,98935. GitHub ActionsFree lesson

Context and Expression Syntax

Using context objects like github, env, and secrets with ${{ }} expression syntax in workflows.

Context and Expression Syntax

What you'll learn: How to dynamically access runtime data and secrets in GitHub Actions workflows using context objects and expression syntax.

The Core Idea

GitHub Actions workflows aren't static scripts—they need to respond to runtime conditions, access secrets, and reference environment details. Context objects are special data structures that hold information about the workflow run, repository, environment variables, and secrets. You access these using expression syntax: ${{ }}.

Think of contexts like drawers in a filing cabinet: each drawer (github, env, secrets) holds specific types of information. The ${{ }} syntax is your key to opening those drawers and pulling out exactly what you need.

Common Context Objects

github context — Contains workflow run metadata like repository name, branch, commit SHA, and triggering event:

run: echo "Running on branch ${{ github.ref }}"

env context — Accesses environment variables defined in your workflow or job:

env:
  DEPLOY_ENV: production
steps:
  - run: echo "Deploying to ${{ env.DEPLOY_ENV }}"

secrets context — Safely retrieves encrypted secrets stored in your repository settings:

- run: |
    echo "API Key is secured"
    curl -H "Authorization: Bearer ${{ secrets.API_TOKEN }}"

Expression Syntax Rules

Expressions are evaluated by GitHub Actions before executing steps. You can use them in most workflow properties:

  • In if conditionals: if: ${{ github.ref == 'refs/heads/main' }}
  • In run commands or action inputs
  • Cannot be used inside other expressions (no nesting ${{ ${{ }} }})

Key Takeaway: Context objects (github, env, secrets) combined with ${{ }} expression syntax let you dynamically access runtime information, environment variables, and secrets, making workflows flexible and secure.