How To Create Continuous Deployment With Visual Studio, Azure, And Visual Studio Team Services
When you create an app on your computer, this is when everything seems to work perfectly. When ready, you will move an app to a staging environment for testing, and then finally move it to production. The process for doing all this can be time-consuming and fraught with errors. Now, major cloud players are working to make that process as streamlined as possible and I will walk you through the entire process.
See YouTube video:
What is CICD?
CICD stands for continuous integration & continuous delivery (also referred to as continuous deployment). With CI, you are regularly merging code changes to ensure those changes work (or integrate) with the existing codebase and allow you to perform testing. With CD, you are repeatedly pushing code through a deployment pipeline where it is built, tested, and then deployed. With CD, you may deploy your code to a staging (test, dev) environment or you might automatically publish your code to production.
Who supports CICD?
This approach of your code moving through an automated pipeline, compiling, and releasing code is not new, but cloud-based solutions like Microsoft’s Azure and Amazon’s AWS are adopting CICD into the development workflow. While CICD as a term and a technology has been around for some time, the ability to effortlessly move your code from a computer to a master repository and then to staging or production in the cloud is still very new. You will find all sorts of capabilities labeled beta or preview throughout most cloud solutions today.
Git and CICD
The one thing all the CICD tools have in common is they prefer your project uses a Git repository. You can host that repository internally, but the more common approach is to host your solution on GitHub. Microsoft offers the popular Visual Studio Team Services that allow you to create Git repositories and quickly set up CICD within Azure.
Set up the environment
For this article and attached video, you will use the following tools:
- Visual Studio 2017 (2015 works, but I believe you may need to download a Visual Studio Team Services Git solution before you can get started).
- Visual Studio Team Services (I use the free level).
- Azure (I use Dev Essentials to make use of free credits).
Azure CICD workflow
As you can see in the image below, you will create and update the app on a local computer with a local Git repository. When ready, you will commit the code to the master repository that, in this case, happens to be Visual Studio Team Services (VSTS). Finally, you will set up Azure to look for changes to that repository. Once Azure sees there is new code, it will download, compile, and run the new solution.
When integrating VSTS with Azure, you have a few options. Of course, one option is you can create your integration using PowerShell, Bash, or some other custom code. The second is to allow VSTS to push your code up to Azure. The third and final option is to have Azure wait for changes to your repository and take action when necessary. Personally, I like the third option because you may have one person managing your organization’s cloud services and another maintaining the Git repository. Also, Microsoft’s current documentation seems to point to the best method of using the Azure cloud to do the integration, but I am not sure if it is a preference thing or part of their future direction.
Create the initial project
Automated CICD is not available for all solution types, but it certainly is available for web apps. In the associated video, I walk you through the process of creating the project, which includes the following steps:
1. Create a new Asp.Net web application (MVC).
2. Add the application to a local Git repository.
Set up VSTS
Once your project is in place, you will use Visual Studio to upload your project to VSTS by following these steps:
1. Publish the repository to VSTS.
2. Verify the project is available on your VSTS site.