Web application development with .NET Core and Azure DevOps

CATEGORIES

Blog

Initial setup of the environment

In my previous post “Azure DevOps Services – cloud based platform for collaborating on code development from Microsoft” I presented the basic information about Azure DevOps capabilities. Now, I will focus on the details. Mainly, I will build together a full CI/CD pipeline for automated builds and deployments of sample .NET Core MVC web application to Azure App service.

I assume that based on my previous post, a new project in Azure DevOps is created and you have access to it :). Before the fun begins, let’s setup a service connection between our CI/CD server and the Azure Portal. Navigate to the Azure portal. Service connections can be limited to subscription or resource group level. In our sample case we will set scope to the resource group. First, create a new resource group in Azure:

Azure DevOps

 

Ok, the resource group is ready, navigate now to the settings panel in Azure DevOps, then select the “Service connection” sub-category, and add a new “Azure Resource Manager” service connection:

Azure DevOps

After the confirmation, the provided values will be validated. If everything was provided correctly, the newly created service connection will be saved and ready to use in CI/CD pipelines configuration.

First important thing is ready, now let’s focus on accessing to the Azure Repos GIT repository. In the Azure DevOps user profile you can easily add your existing SSH public key. To do this, navigate to the “SSH public keys” panel in your profile and add your SSH key:

Azure DevOps

 

Later on, clone our new empty repository to the local computer. In the “Repos” section in Azure DevOps portal you can find the “Clone” button which shows a direct link dedicated for cloning. Copy the link to the clipboard and run your local GIT bash console, and run “git clone” command:

 

Azure DevOps

 

One warning occurs, but it is ok – our repository is new and empty 🙂 Now, our environment is ready, then we will create a new project and its code will be committed to our repo.

 

Creation of a development project and repository initialization

I will use the Visual Studio 2017 but here we do not have a limitation to a specific version. When IDE will be ready, navigate to the project creation action, then select “Cloud” and “ASP.NET Core Web application”:

Azure DevOps

 

In next the step, we can specify the framework version and target template. I will base on the ASP.NET Core 2.1 Framework and MVC template:

Azure DevOps

After a few seconds a new sample ASP.NET Core MVC project will be generated. For our purpose it is enough to start the fun with Ci/CD pipeline configuration on the Azure DevOps side. This application will be used as a working example. Dealing with code and implementation of magic stuff inside the application is not a purpose of this post. When the project will be ready, you can run it locally, and after testing commit the code to our repository:

Azure DevOps

Build the pipeline (CI) by visual designer

Our source code is in the repository, so let’s create a build pipeline for our solution. Navigate to the “Pipelines” section, next “Builds” and click “Create new”. In this example we will create our build pipeline from scratch with visual designer. If the pipeline would be committed to the repo in a YAML file (Pipeline as a code) then we have a possibility to load the ready pipeline from the file as well.

 

Azure DevOps

 

The full process contains three steps. At the beginning, we must specify where our code is located. The default option is the internal GIT repository in our project in the Azure DevOps. In our case this selection is correct. In second step, we can use one of the pre-defined build templates. Our application is based on the .NET Core framework, so I will select the ASP.NET Core template. After that the pre-defined agent job will be created for us. The job will contains steps like NuGet packages restoring, building of our solution, testing (in our app test doesn’t exist) and final publishing of the solution to package which will be used in the release pipeline. Here we can also export our pipeline to a YAML file:

Azure DevOps

 

On the “Triggers” tab the “Continuous integration” feature is not activated by default. Let’s enable them manually:

 

Azure DevOps

 

After saving all changes in the pipeline, our setup CI build pipeline is ready. Below you can see the sample action triggered by committing new changes in the repository. The new “CI build” runs immediately after new changes in the application code have been committed. Also email notifications will be sent to all subscribers. In the reason field, we can see “Continuous integration”. The icons in the email and in the build panel in the portal are an easy way to show the status of the build:

Azure DevOps

 

Release pipeline (CD)

Now we will take care of the automatic release of our application to App Service on Azure. At the beginning, we need to create an App Service instance in the resource group, which has been selected to the service connection:

 

Azure DevOps

Ok, when the deployment is finished, we can start the creation process of the release pipeline in Azure DevOps. First we have to decide which template from the pre-defined list we will use. For our solution the “Azure App Service deployment” will be a good choice:

 

Azure DevOps

Next we must specify the source of artifacts. In our case, we will use the results of our build pipeline created in the previous steps:

Azure DevOps

 

Stages in the pipeline can be also renamed. This is a good practice in huge pipelines. We can observe what’s happened in each stage:

Azure DevOps

 

In the general settings for our new stage-agent, we must fill three very important parameters. First one is to specify which service connection the release pipeline will use, secondly, we must select the type of the application deployed to the  App Service. In the third parameter, we must put in the name of the existing App Service instance. We already created one at the beginning of this part of post.

 

Azure DevOps

 

Next in the configuration is to select the localization of the published application package. In our case this localization looks like this:

Azure DevOps

 

In a similar way like in the CI pipeline we need to enable the trigger in our newly created CD pipeline. To do that, we must click on the light icon on the artifact source and enable the trigger for the build:

Azure DevOps

 

It was the last step in the configuration. Looks like we are ready to commit some changes and check the final functionality 🙂

 

Final check

Let’s test our new full CI/CD pipeline then:

1. Add the new code in the application:

In the controller:

Azure DevOps

In the view:

Azure DevOps

2. Commit the changes to the repository:

Azure DevOps

 

3. Our CI build pipeline started automatically and is ready:

Azure DevOps

 

4. I received an email with confirmation of the correct building:

Azure DevOps

 

5. The release CD pipeline started automatically after success. The build from the CI pipeline and deployment is ready:

Azure DevOps

 

6. Changes have been deployed to Azure App Service and are visible:

Azure DevOps

 

As we can observe, the configuration of the full CI/CD pipeline for ASP.NET Core MVC web application is pretty easy. However, you must have some knowledge related to the configuration this stuff on the Azure DevOps side.

We hope you will enjoy this post and this step-by-step guide will be useful for your future experience with Azure DevOps!

***

This post is the 2nd part in our Azure DevOps series. Check out the other posts:

#1: Azure DevOps Services – cloud based platform for collaborating on code development from Microsoft

#3: Azure Cosmos DB – Multi model, Globally Distributed Database Service

Blog

Starter for 10: Meet Jonna Iljin, Nordcloud’s Head of Design

When people start working with Nordcloud, they generally comment on 2 things. First, how friendly and knowledgeable everyone is. Second,...

Blog

Building better SaaS products with UX Writing (Part 3)

UX writers are not omniscient, and it’s best for them to resist the temptation to work in isolation, just as...

Blog

Building better SaaS products with UX Writing (Part 2)

The main purpose of UX writing is to ensure that the people who use any software have a positive experience.

Get in Touch

Let’s discuss how we can help with your cloud journey. Our experts are standing by to talk about your migration, modernisation, development and skills challenges.








    Azure DevOps Services

    CATEGORIES

    BlogTech Community

    This post will show the main features of the Azure DevOps services.

    Few words about Microsoft Azure DevOps

    Azure DevOps has been created as a successor of Visual Studio Team Services, mainly known as VSTS. In general, there is no one application. We should look at this service as a set of tools, which can help in several ways people who use the “DevOps” methodology for continuous delivery of the highest value for their end-users. Summarising, we can use Azure DevOps for storing our source code in the GIT repositories, setup an automatic build and release solutions for every new piece of code committed to the repository, as well as plan & track all the activities related to Agile project management on dedicated backlog and set of useful boards.

     

    Project setup

    Before we start building our pipelines and committing code, we must create a project in Azure DevOps. To do that, we need an account in the service. Account creation is free. When the account will be ready, the new user is able to fill in all the information related to the organisation, and after that he can create a new empty project.

    In the Azure DevOps project settings pane, the project owner can decide which features will be used. Below the picture shows a full list of available services. Let´s focus in detail on some of them:

     

    Azure DevOps

    Boards

    When a new project starts, all the features should be divided into tasks and described in the project backlog. This is a place, where the Product Owner can create a proper order of activities, which will be implemented by the Development Team. Azure DevOps board features provide a way to create Epics, Features, User Stories filled by Tasks etc. Here testers can also create Test-Case scenarios and report bugs or issues.

    Azure Repos

    Azure DevOps provides an access to unlimited, private GIT repositories – Azure Repos. GIT is one of the most popular versions of control systems, with full scope of features like branching, tagging or pull requesting which are covered by the build-in repos service inside Azure DevOps. External providers like GitHub, Bitbucket or GitLab can be used as source repositories of an application code, when a build pipeline will be created in the Azure DevOps.

     

    Build pipelines

    Information about the build pipeline setup is stored inside the GIT repository in a YAML file. When the file exists in the repository, we can start the configuration process of our new build, and Azure DevOps will automatically use a pre-defined pipeline stored as a code inside project repository. This feature is really great. When in the future someone will need to re-create the pipeline, all information is stored in one file, which can also be used as a some kind of a process documentation.

     

     

    If the new project is configured, Azure DevOps project owner can use one of the pre-defined templates for build pipeline, and not only Microsoft solutions are supported:

     

    When the build pipeline is ready, we can easily queue our build, and when completed, track building history on dedicated pane:

     

    If something went wrong during the building process, all information will be available in the logs section inside the broken build. History pane shows also all additional information like the branch from which the code has been used for building, an icon adequate for the build status, and the unique number of the build from the solution.

     

    Release pipelines

    Release pipeline is a functionality which allow us to deploy our application to one or more destinations. Before we begin, we need to setup the correct service connections in the project settings pane. For example, if we want to deploy our web application to Azure App Service, we must configure service connection between Azure DevOps and Azure Resource Manager service. Part of the available service connections are shown below:

     

    In the first step we can decide if we want to use one of the pre-defined stage templates, or if we want to start with an empty job and setup all the steps on our own. Available templates for the stages are for example:  “Azure App Service Deployment”, “Deploy to Kubernetes cluster” etc. Picture below shows a part of the pre-defined templates list:

    A pipeline can be edited interactively. Every stage can be modified individually, and can consist of a set of tasks like: “Azure PowerShell” script execution, whole “Azure Resource Group Deployment” or even an interaction with Linux or macOS system by “Bash” script.

    A sample of the release pipeline is shown below. As the artifacts source for a pipeline has been selected, the build is created in the previous step. We can of course create the release pipeline without an associated build. If our repository contains only scripts, which do not have to be build, we can set as an artifacts source the GIT repository directly.

     

    ***

    This post is the 1st part in our Azure DevOps series. Check out the other posts:

    #2: Web application development with .NET Core and Azure DevOps

    #3: Azure Cosmos DB – Multi model, Globally Distributed Database Service

    Blog

    Starter for 10: Meet Jonna Iljin, Nordcloud’s Head of Design

    When people start working with Nordcloud, they generally comment on 2 things. First, how friendly and knowledgeable everyone is. Second,...

    Blog

    Building better SaaS products with UX Writing (Part 3)

    UX writers are not omniscient, and it’s best for them to resist the temptation to work in isolation, just as...

    Blog

    Building better SaaS products with UX Writing (Part 2)

    The main purpose of UX writing is to ensure that the people who use any software have a positive experience.

    Get in Touch

    Let’s discuss how we can help with your cloud journey. Our experts are standing by to talk about your migration, modernisation, development and skills challenges.