Deployment Pipeline Controls
This lesson explains branch rules, code owners, workflow triggers and environments with approvals.
Learning outcomes
After completing this lesson, you will be able to:
- Describe branch protection rules and rulesets.
- Explain how CODEOWNERS enforces reviews.
- Identify how triggers and environments control deployments.
Branch protection and rulesets
Branch protection rules and the newer rulesets protect important branches such as main. Typical rules require a pull request before merging, a minimum number of approvals, dismissal of stale approvals after new commits, passing required status checks (build and tests), an up-to-date branch, and resolved conversations, and they block force pushes and deletion. Rulesets can apply to many branches by pattern, across repositories in an organization, and can allow bypass only for specific roles.
Protecting main
Code owners
A CODEOWNERS file (in .github/, the root or docs/) maps path patterns to users or teams. GitHub requests reviews from the owners of changed files, and with the "require review from code owners" rule, their approval is mandatory before merging. The last matching pattern in the file wins.
# .github/CODEOWNERS
* @contoso/app-team
/database/ @contoso/database-team
/database/Security/ @contoso/security-team
/.github/workflows/ @contoso/platform-teamReading CODEOWNERS
Triggers, environments and approvals
Workflow triggers separate validation from deployment: pull_request runs build and tests for proposed changes, push to main (optionally filtered with paths: ['database/**']) starts a deployment, and workflow_dispatch allows manual runs. Deployment jobs reference an environment, such as staging or production, whose protection rules control what happens next, as the following steps show.
-
Branch restriction
The environment accepts deployments only from main (or selected branches or tags).
-
Required reviewers
Designated people or teams must approve before the job starts; self-review can be prevented.
-
Wait timer
An optional delay gives time to cancel a deployment.
-
Scoped credentials
Environment secrets and the environment-scoped federated credential become available only after approval.
Pipeline authentication completes the picture: each environment uses its own identity, and the production identity's database user has only the permissions deployments need, such as db_ddladmin and data-writing permissions for reference data, not server administration. The deployment history of each environment records who approved and what ran.
Triggers and environment rules
Governing production schema changes
A company requires that changes to files under /database are approved by the database team, that nothing merges to main without passing tests, and that production deployments wait for approval by an operations lead. Which controls meet these requirements?
Add /database/ @org/database-team to CODEOWNERS and enable required code owner reviews; protect main with a ruleset that requires pull requests and the test workflow as a required status check; and make the deployment job target a production environment with the operations lead as a required reviewer. Requiring two approvals without CODEOWNERS would not guarantee a database team reviewer, and a manual workflow_dispatch trigger alone does not record an approval.
When several CODEOWNERS patterns match a file, which applies?
Show answer
The last matching pattern in the file.
Exam Tips
Remember for the exam
- Mandatory reviews by a team for certain paths: CODEOWNERS with required code owner review.
- No merge without passing tests: required status checks on main.
- Human approval before production: environment required reviewers.
- Validate on pull_request; deploy on push to main or workflow_dispatch.