Contexts: Accessing Runtime Information
What you'll learn: How to use GitHub Actions contexts to dynamically access workflow metadata and runtime information during execution.
What Are Contexts?
Think of contexts as read-only dictionaries that GitHub automatically populates with information about your workflow run. Just as a chef has access to information about their kitchen (temperature, available ingredients, time), your workflow has access to runtime details through contexts.
Contexts let you retrieve data about the workflow execution, repository, runner environment, and more—all without hardcoding values.
Core Context Objects
github context: Contains metadata about the workflow run itself—who triggered it, which branch, commit SHA, event type, and repository details.
- name: Show GitHub context info
run: |
echo "Repository: ${{ github.repository }}"
echo "Branch: ${{ github.ref }}"
echo "Triggered by: ${{ github.actor }}"
echo "Commit SHA: ${{ github.sha }}"
env context: Accesses environment variables you've defined at workflow, job, or step level (remember lesson 1705?).
- name: Use environment variable
run: echo "Build number: ${{ env.BUILD_NUMBER }}"
secrets context: Securely retrieves encrypted secrets stored in your repository (from lesson 1706).
- name: Deploy using credentials
run: deploy.sh
env:
API_KEY: ${{ secrets.PRODUCTION_API_KEY }}
Context Syntax
Access contexts using the ${{ }} expression syntax. These expressions evaluate during workflow execution, providing dynamic values based on the actual run.
Key Takeaway: GitHub Actions contexts (github, env, secrets) give your workflows access to runtime metadata, environment variables, and secure credentials using the ${{ context.property }} syntax—enabling dynamic, data-driven pipeline logic.