DEV Community

Cover image for How to enable Continuous Integration with Azure Pipelines
Olalekan Oladiran
Olalekan Oladiran

Posted on

How to enable Continuous Integration with Azure Pipelines

How to include build validation to validate a Pull Request

  • Firstly, we need to import a Git repository to work with using this link: https://github.com/MicrosoftLearning/eShopOnWeb.
  • Import a build pipeline called eshoponweb-ci-pr.yml by clicking pipelines in your project Image description
  • Click Create pipeline Image description
  • Choose Azure Repos Git (YAML) Image description
  • Choose your repository Image description
  • Choose Existing Azure Pipelines YAML File Image description
  • Choose /.ado/eshoponweb-ci-pr.yml Image description
  • Save the pipeline definition by clicking save Image description
  • Go back to your newly created pipeline by clicking pipeline under Pipelines section and rename the pipeline. Note that the new pipeline will assume the name of the project Image description

How to Add Branch policies

  • Click Repos and select Branches Image description
  • Click the ellipsis button in front of the main branch among the list of branches and select Branch policies Image description
  • Enable Require minimum number of reviewers, change Minimum number of reviewers to 1 and tick Allow requestors to approve their own changes in the Branch policies pane. Image description
  • Scroll to Build validation section, click +, select the pipeline created earlier, leave other settings as default and click save. Image description Image description

How to work with Pull Requests

  • Click on Repos and select branches Image description
  • Click New branch to create a branch based on the main branch Image description
  • Click on the newly created branch to open it Image description
  • Look for /eShopOnWeb/src/Web/Program.cs and click it to open it Image description
  • Click Edit Image description
  • Add this // Testing my PR to the first line and select Commit Image description
  • Click commit Image description
  • Click Create a Pull Request. Image description
  • Provide a title for the pull request and leave other settings as default. Image description
  • Click Approve to approve the pull request. Image description Image description
  • Click on complete Image description Click complete merge Image description

Image description

How configure CI Pipeline as Code with YAML

  • We need to create a new pipeline by importing the CI pipeline named eshoponweb-ci.yml
  • Import a build pipeline called eshoponweb-ci.yml by clicking pipelines in your project Image description
  • Click Create pipeline Image description
  • Choose Azure Repos Git (YAML) Image description
  • Choose your repository Image description
  • Choose Existing Azure Pipelines YAML File Image description
  • Choose /.ado/eshoponweb-ci.yml and click continue Image description
  • Save the pipeline definition by clicking save Image description

How to enable Continuous Integration

  • Click Edit to edit the pipeline Image description
  • Replace the first 3 comments with: trigger: branches: include:
    • main paths: include:
    • src/web/*
  • Click save Image description
  • Tick Create a new branch for this commit, leave the default branch name and tick Start a pull request. Click save after Image description
  • Rename the pipeline by going to pipelines, click the ellipsis button in front of pipeline and click rename. Image description
  • Provide a new name and click save Image description
  • Click Repos, select pull request and click Update eshoponweb-ci.yml for Azure Pipelines Image description
  • Click Approve to approve the pull request Image description
  • After 1 reviewer has approved, click complete Image description
  • Click complete merge in the Complete pull request pane. Image description

Testing the CI pipeline

  • Create a new branch on the main branch by clicking Repos and selecting branches Image description
  • Click New branch Image description
  • Provide a name for the branch and click create. Image description
  • Click on the new branch to open it and look for /eShopOnWeb/src/Web/Program.cs file Image description
  • Click Program.cs to open it and click Edit Image description
  • Delete // Testing my PR on the first line we added before and click commit Image description
  • Click Commit Image description
  • Click create a pull request Image description
  • In the New pull request pane, leave all settings as default and click create Image description
  • A pane showing at least one reviewer must approve will be displayed because of branch policies applied to the main branch.
  • Click approve Image description
  • Click complete after 1 reviewer has approved Image description
  • Select complete merge Image description
  • Going back to our pipelines, we will see that the renamed pipeline was automatically triggered after the code was merged
  • Select the pipeline and click build under Jobs Image description

Image description

Top comments (0)