Maven / 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.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
