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

Environment Variables in Workflows

Setting and using environment variables at workflow, job, and step levels for configuration.

Environment Variables in Workflows

You'll learn how to configure workflows, jobs, and steps using environment variables at different scopes for flexible, reusable pipeline automation.

What Are Environment Variables in Workflows?

Environment variables in GitHub Actions let you store configuration values, paths, and settings that your workflow needs to run. Think of them like labeled boxes on a shelf—some boxes sit at the top shelf (workflow-level, available everywhere), some on the middle shelf (job-level, available to one job's steps), and some on the bottom shelf (step-level, available only within that single step).

Setting Variables at Different Levels

Workflow-level variables apply to all jobs and steps:

env:
  APP_NAME: my-application
  NODE_ENV: production

Job-level variables apply only to steps within that specific job:

jobs:
  build:
    env:
      BUILD_VERSION: 1.2.3
    steps:
      - run: echo "Building version $BUILD_VERSION"

Step-level variables apply only to that single command:

- name: Deploy
  env:
    DEPLOY_REGION: us-east-1
  run: ./deploy.sh

Why Use Different Scopes?

Place variables at the narrowest scope needed. If only one step needs a database password, define it at the step level—not globally where other steps might accidentally expose it. Use workflow-level for truly shared configuration like the application name or environment type.

Variables at narrower scopes override broader ones, giving you flexibility to customize behavior while maintaining defaults.

Key Takeaway: Environment variables in GitHub Actions can be scoped at workflow, job, or step levels, allowing you to configure pipeline behavior precisely where needed while maintaining security and clarity through appropriate scope boundaries.