- Maintain clean, DRY workflows
- Easily update container names, registry endpoints, and other parameters
- Secure sensitive data using GitHub Secrets
variable-secrets.yaml) that builds, pushes, and deploys a Docker image:
- GitHub Actions builds the Docker image.
- Logs in to Docker Hub.
- Pushes the image.
- Runs the container in the
deployjob, which depends ondocker.
Overview of Environment Variable Scopes
1. Step-Level Environment Variables
Define variables in an individual step. This is ideal for values that aren’t reused elsewhere.$VAR_NAME${{ env.VAR_NAME }}(recommended when mixing with expressions)
2. Job-Level Environment Variables
Apply the same variables to all steps in a job by declaring them underjobs.<job_id>.env:
env under a job cascades to every step. You can still override or augment variables at the step level.
3. Workflow-Level Environment Variables
Declare variables at the top of your workflow to make them available across all jobs and steps:Never hard-code sensitive values like passwords or API keys. Store them in GitHub Secrets and reference them with
${{ secrets.YOUR_SECRET_NAME }}.Verifying Your Workflow
- Commit and push your changes.
- Open the Actions tab in your repository.
- Watch the docker and deploy jobs run sequentially.
- Expand each step to confirm that variables are correctly substituted and that secrets remain masked.
Use
${{ env.VAR_NAME }} when combining expressions with literal strings to ensure consistent parsing.