Using CI, allows you to merge the code changes in order to ensure that those changes work with the existing codebase and allows you to perform testing. On the other hand, using CD you are repeatedly pushing code through a deployment pipeline where it is a built, tested, and deployed afterwards. This CI/CD team practice automates the build, testing and deployment of your application, and allows complete traceability in order to see code changes, reviews and test results.
In order to create a CI build and a release pipeline and Release Management that is going to deploy the code into Azure, all you need is an existing web based application and an extension from the marketplace.
In order to use Continuous Delivery Tools for Visual Studio extension you just need to enable it. The Continuous Delivery Tools for Visual Studio extension makes it simple to automate and stay up to date on your DevOps pipeline for ASP.NET and other projects targeting Azure. The tools also allow to improve your code quality and security.
- Go to Tools, choose Extensions and Updates.
- From the prompted window, select Continuous Delivery Tools for Visual Studio and click Enable.
*If you don’t have installed Continuous Delivery Tools go to Online Visual Studio Marketplace, search for “Continuous” and download it.
In this step you are going to create a project in Team Services and put your project code there without leaving your IDE. Team Services is a tool that allows you to build a continuous integration and continuous delivery.
- Go in the Solution Explorer, right click on your web-based project.
- Click on the new context menu Configure Continuous Delivery.
- New window is displayed Configure Continuous Delivery. Click on the Add this project to source control plus button.
- Click on the Publish Git Repo button located in the Publish to Visual Studio Team Services section in Team Explorer.
- Your Microsoft Account is automatically fetched from your IDE. Also is displayed the Team Services Domain which will be used and your Repository Name. Click on the Publish Repository button in order to create a project in Team Services.
- After the synchronization is finished you will see that your project is created in the Team Explorer.
Now your project is created into Team Services account (the source code is uploaded, there is a Git Repository and it is generating continuous delivery pipeline automatically).
- In the output window you can see that your CI/CD are setting up for your project.
- After a while, you are going to get 3 different links:
- Link to the build
- Link to the release
- Link to the assets created in Azure which is going to be the target for your deployment. (application service)
A build definition is the entity through which you define your automated build process. In the build definition, you compose a set of tasks, each of which perform a step in your build.
- Choose the Build Definition link provided in Output window and copy.
- Paste it in a browser in order to open the project containing your application in Team Services.
- The summary for the build definition is displayed. You can see that the build is already running.
- Click on the build link.
- It is shown an output of your build server which is running your build automatically.
- Click on the Edit build definition.
- You are going to see all the tasks that were automatically set up in order to be able to build the code that you had inside your Visual Studio. You can:
- Add additional task
- Customize the tasks that are already there
Each task has a Version selector that enables you to specify the major version of the task used in your build or deployment. When a new minor version is released (for example, 1.2 to 1.3), your build or release will automatically use the new version. However, if a new major version is released (for example 2.0), your build or release will continue to use the major version you specified until you edit the definition and manually change to the new major version.
- Click on the Test Assemblies.
- You can see a little flag icon which means that there is a new available preview version of this task. Click on the Flag Icon and choose version 2* in order to preview.
- There are several new items shown for the Test Assemblies One of them is Run only impacted tests. This is an item which allows to tools to analyze which lines of code were changed against the tests that were runned in the past and you will know which tests execute which lines of code (you will not have to run all of your tests, you are able to run only the tests that were impacted with the changes).
- Run tests in parallel on multi-core machines is an item which allows your tests to run in such a way to use all the cores you have available. Using this item you will effectively increase the number of tests running at the same time, which will reduce the time to run all the tests.
- Code coverage enabled is another very useful item that during executing your unit test, VSTS will monitor the code as it is being tested and highlight which lines of code were actually covered with your tests.
A task is the building block for defining automation in a build definition, or in an environment of a release definition. A task is simply a packaged script or procedure that has been abstracted with a set of inputs. There are some built-in tasks in order to enable fundamental build and deployment scenarios.
- Click on the Add Task plus button in order to create new additional task.
- An enormous list of tasks is displayed that can be run out of the box that allow you to target any language/platform. (Chef support, CocoaPods, Docker, NodeJS, Java).
- If you want to install another feature or extension which is not listed, simply click on the link Check out our Marketplace which is displayed above the list of tasks.
- In new tab is opened Visual Studio Marketplace with all additional features and extensions. All of them are open source and you can actually go to GitHub and see their source code. You also can write your own task using PowerShell or NodeJS.
Variables are a great way to store and share key bits of data in your build definition. Some build templates automatically define some variables for you.
- Go and click on the second tab named Variables (next to the tab Tasks).
- Click on the padlock located next to the variable value, in order to encrypt it.
- After encrypting, the value of the variable is displayed with asterisks, and no one can see this value except the person who encrypted it.
On the Triggers tab you specify the events that will trigger the build. You can use the same build definition for both CI and scheduled builds.
- Go and click on the third tab named Triggers, where actually you can setup your Continuous Integration.
- Enable the box Disable this trigger means that this build will run automatically whenever someone checks in code or with other words when a new version of the source artifacts is available.
If the build process fails, you can automatically create a work item to track getting the problem fixed. You can specify the work item type. You can also select if you want to assign the work item to the requestor. For example, if this is a CI build, and a team member checks in some code that breaks the build, then the work item is assigned to that person.
- Go and click on the fourth tab named Options.
- Enable the box Create Work Item on Failure. CI builds are supposed to build at every check in, and if some of them fail because the developer made an error, you can automatically create a work item in order to track getting the problem fixed.
- Default agent queue option is displayed in the second half of the Options In the drop down list are listed all available pools:
You can see the summary of the build, in other words everything that happened during the build, following the next steps:
- Click on the Summary button located in the upper right corner.
- Click on the build number, located in the Recently completed.
- The build summary is displayed. You are able to see:
- Code coverage
- All work items and tasks
A release definition is one of the fundamental concepts in Release Management for VSTS and TFS. It defines the end-to-end release process for an application to be deployed across various environments. Remember that you as a developer, never have to leave VS in order to deploy application from VS into Azure.
- Click on the succeeded deployment link, displayed in the Build Summary page, in the Deployments section. This is a CD portion of a CI/CD.
- A release definition is displayed that deployed the code into Azure.
- Click on the three dots located next to the particular release definition.
- From the displayed context menu, select Edit.
- The deployment is very similar to the build system. All it do is taking a result of CI and deploying it in Azure using CD. In this page there are displayed:
- Series of environments
- Tasks that you want to perform in each environment
Microsoft Azure is a cloud computing service for building, testing, deploying, and managing applications and services through a global network of Microsoft-managed data centers. In this step you will verify if your web application is deployed in Azure, following the next steps:
- Go in your Azure portal.
- Click on the Resource Groups.
- Search for the “demo”.
- Click In the search results on your web project “e2edemo”.
- Open the web application link.
- Click on the Browse button displayed in the upper menu.
- The website which code is running in your Visual Studio should be opened, now hosted in Azure. Now every change that developer makes will immediately be deployed inside Azure environment, which is giving you a true Continuous Delivery.
Continuous Integration is a software development practice in which you build and test software every time a developer pushes code to the application. Continuous Delivery is a software engineering approach in which continuous integration, automated testing, and automated deployment capabilities allow software to be developed and deployed rapidly, reliably, and repeatedly with minimal human intervention.
High-performing teams usually practice Continuous Integration (CI) and Continuous Delivery (CD). VSTS not only automates the build, testing and deployment of your application, but it gives you complete traceability to see everything in the build including changes to your code, reviews, and test results, as a tool which is fully supporting DevOps practices.