1. Baseline Workflow (Hard-coded Values)
Hard-coding credentials like
dockerUsername and s3curePaSsW0rd is insecure and violates DRY.
Always use variables and secrets instead.2. Step-Level Environment Variables
Defineenv per step to remove inline repetition:
Referencing Variables
You can reference environment variables in two ways insiderun: blocks:
- Shell syntax
- GitHub Actions expression
3. Job-Level Environment Variables
Move shared variables to the job level so all steps inherit them:- Job-level
envapplies to all steps in that job. - Step-specific
envvalues (likeDOCKER_PASSWORD) override or extend the job-level settings.
Variable Scope Overview
4. Workflow-Level Environment Variables
Setenv at the workflow root so all jobs inherit the same defaults:
CONTAINER_REGISTRY, DOCKER_USERNAME, and IMAGE_NAME from the workflow-level env.
5. Running the Workflow and Inspecting Logs
Once the workflow runs, GitHub Actions expands and masks sensitive data:Sensitive values like
DOCKER_PASSWORD are automatically masked in the logs.