Scope
This article is part three of a series of four articles on getting an ASP.NET Web App live on Azure App Services using Azure Repos and Azure Pipelines. The previous articles described how to create your Azure DevOps account, create a project, and push your code to Azure Repos using Git.
This is the third article of the series and will walk you through automating your builds each time code is updated in your repository.
Continuous Integration (CI) With Azure Pipelines
Continuous Integration (CI) is the automation of builds and testing of code each time changes are pushed to your code repository; it helps to catch bugs or problems early in the development cycle, which makes them easier and faster to fix.
Azure Pipelines is the Continuous Integration / Continuous Delivery service in Azure DevOps that can build any language targeting any platform. Azure Pipelines has hosted pools of Windows, Linux, & Mac machines that it manages for you so that all your focus is on developing features for your product.
Build Pipeline
Our next step continuing off from the last article is to automate the build process of the .NET web app each time code is pushed to our repository. Jump to ‘Builds’ under ‘Pipelines’ or press the keyboard shortcut G B. (Check out all the Azure DevOps Keyboard Shortcuts).
Next, click on ‘New Pipeline’.
Azure Pipelines supports Azure Repos, GitHub, Bitbucket, and Subversion External Git repositories as a source for the build pipelines.
Select ‘Azure Repos’, and input the correct Project, Repository & Branch (the default is master in this case). Hit Continue.
You will be presented with a wide variety of readymade templates to build pretty much everything from Android and iOS Apps, to Docker, Go Applications, and much more. We’ll go for the ASP.NET template.
The next screen will show the details of the different steps in the build template we’ve chosen.
The output of this build pipeline is called the Artifact. Artifacts are the collection of files or packages produced by the build and used in subsequent tasks, such as distribution or deployment. By default, the artifact is called ‘drop’.
You will notice that as mentioned before, Azure Pipelines has build agents that let you target pretty much any platform, and also supports private build agents.
In your case, there’s no change needed in this template. But if you want to customize this build pipeline, click on the little ‘+’ button on top, and you will get to choose from a wide range of first-party and third-party tasks you can drag and drop into the build pipeline.
One last thing that we need to do is to enable Continuous Integration in the Triggers tab so the build tasks run automatically each time we push changes to the repository.
Click on "Save". The Build Pipeline is now ready.
To test out the build pipeline, make some changes to your local ASP.NET code and push the code to the online repository using the commands described in the previous article.
As soon as the code is pushed, you will see in the Azure DevOps web portal that a build is already in the queue and running.
Clicking on the commit title will show you the build details & logs in real-time, and you can follow the console output for any warnings or errors.
After a few minutes, the automatic build is complete.
The build artifact is available, you can explore its content by clicking on ‘Artifacts’, and then selecting ‘Drop’ in the menu.
As soon as the build is completed, you are also notified by email. You are not required to constantly check the Azure DevOps, it’s basically a "set-up and forgets".
Conclusion
In this part of the Azure DevOps for Web Development series, you have seen how to automate your builds in the cloud using Azure Pipelines, which produced an artifact. In the next article of the series, you will see how to use this artifact to automate your deployments using Release Pipelines.
See also