Interview Prep/GitHub Actions/Contexts, Expressions, Env & Outputs

How do you read an environment-specific variable in a reusable workflow?

AdvancedConceptContexts, Expressions, Env & Outputs
Answer

Bind the job to the environment, then read vars and secrets normally; environment values override repo values once the job is inside the environment.

on:
  workflow_call:
    inputs:
      environment: { type: string, required: true }
jobs:
  deploy:
    environment: ${{ inputs.environment }}
    runs-on: ubuntu-24.04
    steps:
      - run: echo "Cluster ${{ vars.CLUSTER_NAME }}"

Environment secrets are only available inside the job that declares the environment, not to the caller.

All GitHub Actions questions Roadmap: GitHub Actions

More on Contexts, Expressions, Env & Outputs