Maven / GitLab CI Basics Interview Questions
What is the difference between 'only/except' and 'rules' in GitLab CI?
only and except are the original (legacy) keywords for controlling when jobs run. rules is the modern replacement introduced in GitLab 12.3 that provides more flexibility and clearer logic.
| Aspect | only/except | rules |
|---|---|---|
| Introduction | GitLab initial release | GitLab 12.3 |
| Status | Still supported; not deprecated but not recommended for new pipelines | Recommended for new configurations |
| Conflict | Can be used together (but only/except wins if both present on same job) | Cannot be combined with only/except on the same job |
| Logic | Separate allow/deny lists | Sequential rule evaluation - first match wins |
| Flexibility | Limited - only ref, variables, changes, kubernetes | Full expressions, allow_failure, when, start_in |
# Legacy only/except (works but not recommended for new pipelines): deploy-old: script: ./deploy.sh only: - main - tags except: - schedules # Modern rules equivalent (preferred): deploy-new: script: ./deploy.sh rules: - if: $CI_COMMIT_TAG # matches any tag push - if: $CI_COMMIT_BRANCH == "main" when: on_success - when: never
Recommendation: use rules for all new pipeline configurations. It supports complex conditional logic with if, changes, exists, and when in a single keyword, replacing the fragmented only/except approach.
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...
