How to enable Continuous Integration with Azure Pipelines
Olalekan Oladiran
Posted on February 21, 2024
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
- Click Create pipeline
- Choose Azure Repos Git (YAML)
- Choose your repository
- Choose Existing Azure Pipelines YAML File
- Choose /.ado/eshoponweb-ci-pr.yml
- Save the pipeline definition by clicking save
- 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
How to Add Branch policies
- Click Repos and select Branches
- Click the ellipsis button in front of the main branch among the list of branches and select Branch policies
- 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.
- Scroll to Build validation section, click +, select the pipeline created earlier, leave other settings as default and click save.
How to work with Pull Requests
- Click on Repos and select branches
- Click New branch to create a branch based on the main branch
- Click on the newly created branch to open it
- Look for /eShopOnWeb/src/Web/Program.cs and click it to open it
- Click Edit
- Add this // Testing my PR to the first line and select Commit
- Click commit
- Click Create a Pull Request.
- Provide a title for the pull request and leave other settings as default.
- Click Approve to approve the pull request.
- Click on complete Click complete merge
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
- Click Create pipeline
- Choose Azure Repos Git (YAML)
- Choose your repository
- Choose Existing Azure Pipelines YAML File
- Choose /.ado/eshoponweb-ci.yml and click continue
- Save the pipeline definition by clicking save
How to enable Continuous Integration
- Click Edit to edit the pipeline
- Replace the first 3 comments with:
trigger:
branches:
include:
- main paths: include:
- src/web/*
- Click save
- Tick Create a new branch for this commit, leave the default branch name and tick Start a pull request. Click save after
- Rename the pipeline by going to pipelines, click the ellipsis button in front of pipeline and click rename.
- Provide a new name and click save
- Click Repos, select pull request and click Update eshoponweb-ci.yml for Azure Pipelines
- Click Approve to approve the pull request
- After 1 reviewer has approved, click complete
- Click complete merge in the Complete pull request pane.
Testing the CI pipeline
- Create a new branch on the main branch by clicking Repos and selecting branches
- Click New branch
- Provide a name for the branch and click create.
- Click on the new branch to open it and look for /eShopOnWeb/src/Web/Program.cs file
- Click Program.cs to open it and click Edit
- Delete // Testing my PR on the first line we added before and click commit
- Click Commit
- Click create a pull request
- In the New pull request pane, leave all settings as default and click create
- A pane showing at least one reviewer must approve will be displayed because of branch policies applied to the main branch.
- Click approve
- Click complete after 1 reviewer has approved
- Select complete merge
- 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
💖 💪 🙅 🚩
Olalekan Oladiran
Posted on February 21, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.