Use a context value in a step
Read metadata from the current workflow run.
- run: echo "Ref is ${{ github.ref }}"Contexts expose run metadata such as branch, actor, repository, event payload, and more.
Expressions, contexts, env vars, configuration variables, step outputs, job outputs, and dynamic workflow logic in GitHub Actions.
Read data from the workflow run and evaluate conditions dynamically.
Read metadata from the current workflow run.
- run: echo "Ref is ${{ github.ref }}"Contexts expose run metadata such as branch, actor, repository, event payload, and more.
Read configuration values from the `vars` context.
env:
APP_ENV: ${{ vars.APP_ENV }}Use configuration variables for non-secret values shared across workflows.
strategy:
matrix: ${{ fromJson(needs.prepare.outputs.matrix) }}`fromJson()` is useful when one job computes dynamic matrix values for another.
if: contains(github.event.pull_request.labels.*.name, 'deploy-preview')Functions like `contains`, `startsWith`, `endsWith`, and `format` are commonly used in conditions.
Pass values safely between steps and jobs.
Append to `GITHUB_ENV` to persist a variable in the current job.
echo "IMAGE_TAG=${GITHUB_SHA}" >> "$GITHUB_ENV"This is the supported way to set environment variables for subsequent steps in the job.
echo "version=1.2.3" >> "$GITHUB_OUTPUT"Use `GITHUB_OUTPUT` instead of the old deprecated `set-output` workflow command.
- id: version
run: echo "value=1.2.3" >> "$GITHUB_OUTPUT"
- run: echo "Version is ${{ steps.version.outputs.value }}"Give the producing step an `id` so later steps can reference its outputs.
Pass values between jobs through `needs`.
jobs:
prepare:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.meta.outputs.version }}
steps:
- id: meta
run: echo "version=1.2.3" >> "$GITHUB_OUTPUT"
deploy:
needs: prepare
runs-on: ubuntu-latest
steps:
- run: echo "Deploying ${{ needs.prepare.outputs.version }}"Job outputs are the standard way to pass structured values between jobs.
Preserve newlines in an output variable.
{
echo 'notes<<EOF'
cat CHANGELOG.md
echo 'EOF'
} >> "$GITHUB_OUTPUT"Use the heredoc-like delimiter format for multiline values in environment files.