In the previous post, I created basic CI/CD pipeline. In this article, I enhance the pipeline by using multi stage, multi environment.
When I work on projects, I usually use multiple environment such as dev, UAT and production. Azure DevOps support Environment concept and it's integrated as part of pipeline so that I can deploy the application to each environments and I can track the detail separately. See Environments for more detail.
I will add two environment, dev and prod.
Environment and App Service is ready. Let's update yaml.
1. Go to Repo and open azure-pipelines.yml. Then replace the code with following. Update azureSubscription to match your subscription.
- Adding parameters for dev/prod
- Add new stage to deploy to Prod
- Update old deploy stage to deploy to Dev.
Another reason to use environments is to implement approval process.
Azure DevOps supports not only manual approval but also other things such as creating policy or call Azure Functions.
See Define approvals and checks for more detail.
I add manual approval.
3. Add user(s) who should approve. I just added myself and another friend for test but I usually add at least three people. When I add more than one approvers, I have a bit more settings how they should approve.
6. After I approve, the pipeline continues to the next stage.
Not directly related to the pipeline enhancement, but it's important to define the development workflow. Following are some best practices.
- Don't push directly to master branch. Only allow PR merge.
- Set reviewers for each PR.
- Run a pipeline before merge to master branch via PR.
- PR Link to a work item or a bug is mandatory.
- Don't allow to delete master branch.
Azure DevOps has branch policies feature to apply these rules for branches.
There are several triggers to run pipeline which you want to know.
- Push trigger: define in yaml or pipeline settings
- PR trigger: build policy explained above
- Scheduled trigger: Scheduled base trigger
Especially, the push trigger can be set very granular level. See Triggers for more detail.
In this article, I enhanced the pipeline by adding environments and approvals, which are still very basic concepts for DevOps. In the next article, I add more components by using new features to the react application and try another test framework.