DevOps / GitHub Actions Interview Questions
How do you pass environment variables and secrets to a GitHub Actions workflow?
Environment variables and secrets are surfaced inside a workflow through the env: map and the secrets context respectively. They can be declared at three scopes: workflow-level (available to every job), job-level (available to all steps in that job), or step-level (available only to that step).
Environment variables hold non-sensitive configuration values:
env: APP_ENV: production # workflow-level jobs: deploy: runs-on: ubuntu-latest env: REGION: us-east-1 # job-level steps: - name: Print env run: echo "Deploying $APP_ENV to $REGION" - name: Run with step-level var env: LOG_LEVEL: debug # step-level run: ./deploy.sh
Secrets are encrypted values stored in repository Settings → Secrets and variables → Actions. They are injected at runtime and never appear in plain text in workflow logs:
steps: - name: Deploy env: API_KEY: ${{ secrets.API_KEY }} DB_PASS: ${{ secrets.DB_PASSWORD }} run: ./deploy.sh
Secrets are not automatically available as environment variables — you must explicitly map them using env: or pass them as with: inputs to an action. GitHub masks secret values in logs, replacing them with ***, but you should still avoid printing secrets deliberately or constructing log messages that include them.
Organization-level and environment-level secrets also exist and follow the same syntax; they just have a wider or more restricted scope depending on configuration.
More Related questions...