In this blog (Part 2), I take you through on Enabling Continuous Integration (CI) / Continuous Deployment (CD), for the project created on Part 1.
To re-cap, I have made this entire post into two parts for easier understanding and we will focus on Part 2 here:
Part 1 – Creating your first project in Azure DevOps
Part 2 – Enabling the first project in Azure DevOps for Continuous Integration (CI) / Continuous Deployment (CD)
Enabling the first project in Azure DevOps for Continuous Integration
- Now, the next step is to enable continuous integration. Which will keep your build updated based on your changes on project / ARM templates.
- Select Builds on the left pane and click pipeline, which you have created. Click on Edit.
- Click on Triggers and select Enable continuous integration. Click on Save.
- Provide your comment and save.
- Now if you make a change on your template and push it. The deployment will happen automatically.
- From within Visual Studio click on the Code tab and edit Azuredeploy.json file.
- Add storage account to the project and provide name.
- Click Commit when done and push the code. (Please refer part 1 for this activity).
- The deployment will happen automatically due to Continuous Integration and deployment.
- Verify storage account has been created on your Azure tenant.
Enabling the first project in Azure DevOps for Continuous Deployment
To perform continuous deployment, need to copy the files and publish to artifact.
An artifact is a deployable component of your application. It is typically produced through a Continuous Integration or a build pipeline. This means, Code once and share packages across different stages / environment (Dev, Test, UAT & Prod).
- Go to the Pipelines tab, and then select Builds and click on edit.
- Click on + item on Agent Job
- On the new pane, select Copy files and click ADD.
- On the left pane, select copy files to: and fill required information:
- Provide name for task
- Select folder as: Azure template folder.
- Provide target folder.
- Next, we need to publish the Artifact.
- Click on + item on Agent Job.
- On the new pane, select publish build Artifact and click ADD.
- On the left pane, select Publish Build Artifacts: and fill required information:
- Provide name.
- Select path to publish.
- Provide publish location
- Click Save.
Create a release pipeline
A release pipeline is one of the fundamental concepts in Azure Pipelines for your DevOps CI/CD processes. It defines the end-to-end release pipeline for an application to be deployed across various stages.
- Select the action to create a New pipeline. Then select Create a release pipeline.
- Select the action to start with an Empty job. Name the stage Stage1 (Test).
- In the Artifact panel, select + Add and specify a Source (Build pipeline created earlier on this). Select Add.
- To enable the Continuous deployment trigger, click on Lightning bolt to trigger continuous deployment. You can specify any scheduled time for this deployment.
- Select the Tasks tab and select your Stage1 (Test) Select the plus sign (+) for the job to add a task to the job.
- On the Add tasks dialogue box, select deploy and click on Azure Resource Group deployment and click ADD.
- On the left pane, select Azure Deployment: Create or Update Resource Group action on:
- Select Azure Subscription and click on Authorize.
- Select your resource group on your Azure subscription and location.
- The template location will be linked artefact.
- Select your template file (azuredeploy.json) from selection menu.
- Select your template parameter file (azuredeploy.parameters.json) from selection menu.
- Deployment mode: complete.
- On the Pipeline tab, select the stage (Stage1 (Test)) and select Clone.
- Rename the cloned stage (Stage1 (PROD)).
- Note: If needed you can change your Azure subscription details by editing this stage.
- Rename the release pipeline with appropriate.
- Save the release pipeline.
Deploy a release
- To run the Azure template on each stage, you can create a release or make a scheduled trigger.
- Select release and click on Create a release.
- Select which stage needs to have conditions before deployment, in my case production deployment (Stage (PROD)) .
- Click pre-deployment conditions on Prod stage. select After stage of Stage 1 (Test).
- Click on create.
- The release we have created will be deploying and you can check the resource on Azure or verify the logs.
- If you need to perform multiple deploy, select pipeline and click on deploy, choose multiple deploy options.
- After this production stage will have resourced mentioned on ARM template.
Notes: Approvals and gates give you additional control over the start and completion of the deployment pipeline. Each stage in a release pipeline can be configured with pre-deployment and post-deployment conditions that can include waiting for users to manually approve or reject deployments and checking with other automated systems until specific conditions are verified.
In addition, you can configure a manual intervention to pause the deployment pipeline and prompt users to carry out manual tasks, then resume or reject the deployment.
This is the end of this series, Azure DevOps Services to deploy ARM templates with CI/ CD.