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

Environment Variables: Workflow and Job Level

Define and use environment variables at workflow, job, and step scopes.

Environment Variables: Workflow and Job Level

You'll learn how to define environment variables at different scopes in GitHub Actions to control configuration across your entire workflow, specific jobs, or individual steps.

What Are Scoped Environment Variables?

Environment variables in GitHub Actions can be defined at three hierarchical levels: workflow-level (applies everywhere), job-level (applies to one job and its steps), and step-level (applies to a single step). This scoping gives you precise control over which parts of your pipeline see which values.

Think of it like household rules: workflow-level variables are house-wide policies everyone follows, job-level variables are room-specific rules (like "shoes off in the bedroom"), and step-level variables apply to individual tasks (like "use this specific tool for this one chore").

Workflow-Level Variables

Define these at the top of your workflow file using the env: key. Every job and step can access them:

name: Build Pipeline
on: push

env:
  NODE_VERSION: '18'
  DEPLOYMENT_REGION: 'us-east-1'

jobs:
  # All jobs see NODE_VERSION and DEPLOYMENT_REGION

Job-Level Variables

Define these under a specific job's env: key. Only that job's steps see them:

jobs:
  build:
    runs-on: ubuntu-latest
    env:
      BUILD_ENV: 'production'
    steps:
      - run: echo $BUILD_ENV  # sees 'production'
  
  test:
    runs-on: ubuntu-latest
    steps:
      - run: echo $BUILD_ENV  # empty - not defined here

Job-level variables override workflow-level ones with the same name, giving you flexibility to customize behavior per job.

Key Takeaway: Use workflow-level environment variables for global configuration shared across all jobs, and job-level variables to customize settings for specific jobs—scoping reduces redundancy and prevents configuration conflicts.