GitHub Actions: Expressions, Contexts, Variables, and Outputs

Expressions, contexts, env vars, configuration variables, step outputs, job outputs, and dynamic workflow logic in GitHub Actions.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all
## Contexts and expressions
Use repository or organization variables
env:
  APP_ENV: ${{ vars.APP_ENV }}

# Read configuration values from the `vars` context.

Build a matrix from JSON
strategy:
  matrix: ${{ fromJson(needs.prepare.outputs.matrix) }}

# Convert JSON text into a matrix object.

Check if a label is present
if: contains(github.event.pull_request.labels.*.name, 'deploy-preview')

# Use `contains()` in workflow conditions.

## Env files, step outputs, and job outputs
Set an environment variable for later steps
echo "IMAGE_TAG=${GITHUB_SHA}" >> "$GITHUB_ENV"

# Append to `GITHUB_ENV` to persist a variable in the current job.

Set a step output
echo "version=1.2.3" >> "$GITHUB_OUTPUT"

# Append to `GITHUB_OUTPUT` to expose a named output.

Read a previous step output
- id: version
  run: echo "value=1.2.3" >> "$GITHUB_OUTPUT"

- run: echo "Version is ${{ steps.version.outputs.value }}"

# Use the `steps` context to consume a step output.

Promote a step output to a job output
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 }}"

# Pass values between jobs through `needs`.

Write a multiline value to GITHUB_OUTPUT
{
  echo 'notes<<EOF'
  cat CHANGELOG.md
  echo 'EOF'
} >> "$GITHUB_OUTPUT"

# Preserve newlines in an output variable.

Recommended next

No recommendations yet.