Maven / GitLab CI Basics Interview Questions
What are protected branches and protected variables in GitLab CI?
Protected branches and protected variables are security features that control who can push to critical branches and which jobs can access sensitive CI/CD variables.
# Protected variables are set in: # Settings > CI/CD > Variables > Add variable # Tick "Protected variable" checkbox # A protected variable is ONLY available in jobs running on: # 1. Protected branches (e.g. main, production) # 2. Protected tags # Example: PROD_API_KEY is protected: deploy-production: stage: deploy script: - echo "Using: $PROD_API_KEY" # only available because main is protected rules: - if: $CI_COMMIT_BRANCH == "main" # main is a protected branch # feature branches (unprotected) CANNOT access $PROD_API_KEY: test-on-feature: script: - echo "$PROD_API_KEY" # will be empty - variable not available here rules: - if: $CI_COMMIT_BRANCH =~ /^feature/ # Protected branches in GitLab: # Settings > Repository > Protected branches # Can restrict push access to Maintainers, Developers, No one # Can require merge request approval before merging # Can require status checks (pipeline must pass)
| Setting | Controls |
|---|---|
| Allowed to merge | Minimum role required to merge into this branch |
| Allowed to push and merge | Minimum role required to push directly (bypass MR) |
| Allowed to force push | Whether force push is allowed (usually disabled) |
| Code owner approval | Whether CODEOWNERS must approve changes |
Security design: this combination means developers on feature branches cannot access production secrets even if they have access to the project. Only pipelines running on protected branches (typically main or release tags) can use protected variables like production API keys.
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...
