GitHub Actions Tutorial — Contexts
Contexts
Contexts are objects that provide information about the workflow run, the repository, the runner, and more. You access them inside expressions to make decisions and pass data.
Available Contexts
| Context | Description |
|---|---|
github |
Event, repository, actor, ref, sha |
env |
Environment variables |
vars |
Configuration variables |
secrets |
Encrypted secrets |
steps |
Step outputs and outcomes |
needs |
Job outputs and results |
job |
Current job info |
runner |
Runner OS, arch, temp directory |
matrix |
Current matrix values |
strategy |
Matrix strategy config |
inputs |
Workflow dispatch inputs |
github Context
The most commonly used context — provides details about the event and repository:
steps:
- run: |
echo "Event: ${{ github.event_name }}"
echo "Ref: ${{ github.ref }}"
echo "Branch: ${{ github.ref_name }}"
echo "SHA: ${{ github.sha }}"
echo "Actor: ${{ github.actor }}"
echo "Repository: ${{ github.repository }}"
echo "Run ID: ${{ github.run_id }}"
echo "Run number: ${{ github.run_number }}"
echo "Workflow: ${{ github.workflow }}"
Frequently Used github Properties
| Property | Example Value | When |
|---|---|---|
${{ github.event_name }} |
push, pull_request
|
Always |
${{ github.ref }} |
refs/heads/main |
Always |
${{ github.ref_name }} |
main, v1.0.0
|
Always |
${{ github.sha }} |
abc123... |
Always |
${{ github.actor }} |
octocat |
Always |
${{ github.event.pull_request.number }} |
42 |
pull_request events |
${{ github.event.pull_request.head.ref }} |
feature/my-branch |
pull_request events |
${{ github.event.release.tag_name }} |
v2.1.0 |
release events |
steps Context
Access outputs and outcomes from previous steps in the same job:
steps:
- name: Generate version
id: ver
run: echo "version=2.1.0" >> "$GITHUB_OUTPUT"
- name: Check tests
id: test
continue-on-error: true
run: npm test
- name: Use step data
run: |
echo "Version: ${{ steps.ver.outputs.version }}"
echo "Test outcome: ${{ steps.test.outcome }}"
echo "Test conclusion: ${{ steps.test.conclusion }}"
| Property | Description |
|---|---|
${{ steps.<id>.outputs.<key> }} |
Step output value |
${{ steps.<id>.outcome }} |
success, failure, cancelled, skipped
|
${{ steps.<id>.conclusion }} |
Same, but respects continue-on-error
|
needs Context
Access outputs and results from upstream jobs:
jobs:
build:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.ver.outputs.version }}
steps:
- id: ver
run: echo "version=2.1.0" >> "$GITHUB_OUTPUT"
deploy:
needs: build
runs-on: ubuntu-latest
steps:
- run: |
echo "Version: ${{ needs.build.outputs.version }}"
echo "Build result: ${{ needs.build.result }}"
matrix Context
Access the current matrix combination in matrix jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
node: [18, 20]
steps:
- run: echo "OS: ${{ matrix.os }}, Node: ${{ matrix.node }}"
runner Context
Information about the runner executing the job:
steps:
- run: |
echo "OS: ${{ runner.os }}" # Linux, Windows, macOS
echo "Arch: ${{ runner.arch }}" # X64, ARM64
echo "Name: ${{ runner.name }}"
echo "Temp: ${{ runner.temp }}"
echo "Tool cache: ${{ runner.tool_cache }}"
inputs Context
For workflow_dispatch and reusable workflow inputs:
on:
workflow_dispatch:
inputs:
environment:
type: choice
options: [staging, production]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- run: echo "Deploying to ${{ inputs.environment }}"
Common Mistakes
| Mistake | Fix |
|---|---|
| Accessing step output from another job | Use needs context with job outputs, not steps
|
| Context not available | Some contexts are only available in certain scopes (e.g., matrix only in matrix jobs) |
| Typo in context property | Properties are case-sensitive; check docs for exact names |
Missing github.event subproperty |
The event payload varies by trigger type; check webhook docs |
Quick Reference
| Context | Scope | Common Use |
|---|---|---|
github |
Everywhere | Branch, SHA, actor, event data |
env |
Everywhere | Environment variables |
steps |
Same job | Step outputs, outcomes |
needs |
Dependent jobs | Job outputs, results |
matrix |
Matrix jobs | Current matrix values |
runner |
Steps | OS, arch, temp directory |
secrets |
Steps, job env | Encrypted secrets |
inputs |
Dispatch/reusable | Workflow inputs |
← Previous: Expression Syntax
Next: Conditionals →