How To Deploy .NET Core on Azure App Service with Azure DevOps CI/CD — Part 02

Muhammad Rafay
7 min readSep 16, 2023

In my previous post, we successfully deployed a basic “Hello World” application and a Basic Azure App Service. This post will guide you through deploying your application into a production environment.

Architecture Diagram

We’ll walk you through the following steps:

  1. Setting up Azure Repos: We’ll start by creating a repository in Azure to manage your project’s source code.
  2. Pushing Code to Azure Repos: Next, we’ll demonstrate how to push your code to the Azure Repos repository, ensuring it’s securely stored and version-controlled.
  3. Creating a Pipeline: We’ll show you how to set up a deployment pipeline, streamlining the process of building, testing, and deploying your application.
  4. Initiating the Release: Once the pipeline is configured, we’ll guide you through the steps to trigger a release, ensuring your application is ready for deployment.
  5. Deploying Your Code: Finally, we’ll discuss deploying your code to the production environment, making your application accessible to users.

Setting up Azure Repos: -

To get started with Azure Repos for your project, follow these step-by-step instructions:

  1. Create a New Project:
  • Go to https://dev.azure.com/.
  • Sign in with your Azure DevOps account.
  • Click on “New Project” to create a new project.

2. Project Details:

  • Enter the desired name and description for your project.
  • Choose whether you want your project to be public or private (you can set the privacy level here).

3. Repository Creation:

  • Azure DevOps will automatically create a repository when you create a new project. This repository will be associated with your project.

4. Navigate to Azure Repos:

  • Once your project is created, you can find it on the left-hand side of the Azure DevOps interface.
  • Click on “Azure Repos” to access your repositories.

5. Access Repository Links:

  • In the Azure Repos section, you will find links and options to manage your repository.
  • These links allow you to clone the repository, obtain its URL, and perform various repository-related tasks.

You will get the following Output after completing the project creation.

Azure DevOps Repos

Pushing Code to Azure Repos: -

After creating your project and setting up Azure Repos, the next step is to push your code into the Azure Repos repository.

Here are the steps to do that:

  1. Initialize a Git Repository in Your Project Directory:
  • If your project is not already in a Git repository, navigate to your project directory in the terminal and run:

git init

2. Add Remote Origin:

  • Run the following command to add your Azure Repos repository as the remote origin, replacing <repository_url> with the URL of your Azure Repos repository:

git remote add origin <repository_url>

3. Add, Commit, and Push:

  • Use the following commands to add, commit, and push your code to Azure Repos:

git add .

git commit -m “Initial commit”

git push -u origin master

These steps will push your code into the Azure Repos repository, making it available for your CI/CD pipeline and further development. you will get the following Output once your code is in Azure Repos.

Azure DevOps Repos

Creating a Pipeline: -

After successfully pushing your code to Azure Repos, the next step is to set up a pipeline for your project.

Follow these steps to create a pipeline:

  1. Access Azure DevOps:
  • Log in to your Azure DevOps account.

2. Choose a Repository:

  • Click on the “New Pipeline” button.
  • Select your repository source (Azure Git Repos) where your code is hosted.
  • Choose between the classic editor or YAML. For simplicity, let’s choose the YAML this time.

3. Select a Template:

  • Choose the “Starter Pipeline or Existing” template.

4. Define Your Pipeline:

  • Give your pipeline a name. In your case, you can name it something related to your “Hello World” project.

Certainly, here’s an explanation of the provided pipeline,

  1. Trigger: This pipeline is configured to be triggered when changes are pushed to the master branch of the repository. In other words, it will run automatically when code changes are made to the main branch.
  2. Agent Pool: The pipeline specifies the using of an Ubuntu-based agent (vmImage: ubuntu-latest) for its execution. This choice of agent determines the operating system environment in which the tasks will run.
  3. Restore Dependencies: The pipeline begins with a DotNetCoreCLI task configured to run the restore command. This command restores the NuGet packages and project dependencies specified in any .sln (solution) files found in the repository. It uses the 'select' feed to resolve package dependencies.
  4. Build Project: Following the restoration of dependencies, another DotNetCoreCLI task is executed with the build command. This task compiles the code in the same .sln files, essentially building the .NET projects within the repository.
  5. Publish Project: After successfully building the project, a third DotNetCoreCLI task runs the publish command. It is configured to publish web projects (publishWebProjects: true) and specifies additional arguments, including the build configuration ($(buildConfiguration)) and the output directory ($(Build.ArtifactStagingDirectory)). This step prepares the project for deployment.
  6. Artifact Publishing: Finally, a PublishBuildArtifacts task is employed to publish the artifacts generated during the build process. It specifies the path to the artifacts ($(Build.ArtifactStagingDirectory)), assigns them the name 'drop', and indicates that they should be published within the pipeline's container.

Once you create your pipeline, you will get the output something like this,

Azure DevOps Pipeline

7. Save and Queue:

  • After configuring your tasks, click “Save” to save your pipeline.
  • To trigger the pipeline, click “Queue” or “Run” to start the build and deployment process.

8. Monitor Progress:

  • You can monitor the progress of your pipeline in the Azure DevOps interface. It will show you if the build and deployment are successful or if there are any issues.

Once your pipeline is successful build, you will get the following Output,

Azure DevOps

You will also check the pipeline publishes the artifact where our build configuration is stored, which we use for deployment.

Azure DevOps

Initiating the Release:

After the artifact has been published, the next step involves setting up a release process to deploy the code to the Azure App Service. Follow these steps for a seamless deployment:

  1. Access the Release Section: To initiate the deployment process, navigate to the left-hand sidebar of your Azure DevOps environment.
  2. Create a New Release Pipeline: Click “Release” to access the release management section & then click on Next. Create a new release pipeline by selecting the option to create a new one.
  3. Choose an Empty Job Template: Within the release pipeline configuration, opt for an empty job template to give you complete flexibility in defining the deployment process.
  4. Add the Artifact: After selecting your pipeline, click “Add” to include the artifact in your release process.
  5. Select Source Type: In the artifact configuration, select the appropriate source type. In your case, you’ll choose “Hello World Pipeline” as the source of your artifact.
  6. Choose Your Pipeline: Specify your pipeline from the available options. This will be the pipeline responsible for generating the artifact that you intend to deploy.
  7. Add the Artifact: After selecting your pipeline, click on “Add” to include the artifact in your release process.
  8. Configure Deployment Stages:
  • Navigate to your release pipeline’s “Stages” section to define the deployment stages.
  • Type “Deploy Azure App Service” in the search bar to find the appropriate deployment task.
  • Fill out all the details and choose your service connection resource and app service.
  • Then, in the package or folder, choose the appropriate location of the package file
  • Once you have configured all the details, you can save and click on Create Release.

After creating the release, you’ll receive the following output, including the generated build logs for review.

Azure DevOps Release

Deployment:

Once you’ve created the release, navigate to Azure DevOps, copy your domain from the App Service, and verify that our application has been deployed successfully.

Deployment

Conclusion: -

In this blog post, we successfully deployed our application on Azure App Service using Azure DevOps CI/CD. To explore more informative blogs on Azure cloud infrastructure and embrace a cloud-native approach, stay tuned for our upcoming content.

--

--

Muhammad Rafay

Software Engineer, DevOps | Data Pipelines, MLOps, & Cloud Infrastructure | Golang for Scalability & Automation 💻☁️ Open to collabs & sharing insights!