Lesson 4 of 4 Source Control and Deployment Pipelines

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.

Select all that apply

Protecting main

Exam skills 2.3.9

Identify typical branch protection rules for main.

Log in to try this activity Interactive activities are free with an account.

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-team
Scenario questions

Reading CODEOWNERS

Exam skills 2.3.9

Work out which team owns each file.

Log in to try this activity Interactive activities are free with an account.

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.

  1. Branch restriction

    The environment accepts deployments only from main (or selected branches or tags).

  2. Required reviewers

    Designated people or teams must approve before the job starts; self-review can be prevented.

  3. Wait timer

    An optional delay gives time to cancel a deployment.

  4. 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.

Match the pairs

Triggers and environment rules

Exam skills 2.3.9

Match each requirement with the workflow trigger or environment rule that meets it.

Log in to try this activity Interactive activities are free with an account.
Worked example

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.

Check yourself

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.