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.
More on Contexts, Expressions, Env & Outputs
List the available contexts and what each holds.BeginnerWhich contexts can you use in which keys? Give two examples that trip people up.AdvancedWhat are the expression operators and how do comparisons coerce types?IntermediateHow do you write a ternary in GitHub Actions expressions?IntermediateWhat do `contains`, `startsWith`, `endsWith`, `format` and `join` do?BeginnerWhat are object filters (`.*`) and how are they useful?Intermediate