A Step-by-Step Guide to DevOps Service Connections

Deploying ASP.NET Core applications targeting .NET Core 6 and above requires a secure and robust CI/CD pipeline. A key component of this pipeline within Azure DevOps is the creation and management of service connections. These connections enable seamless communication between Azure DevOps and Azure, ensuring that your applications are deployed efficiently and securely. This article offers a detailed walkthrough on establishing a service connection in Azure DevOps, specifically tailored for ASP.NET Core applications.

Prerequisites

Before starting, ensure you have:

  • An active Azure subscription.
  • An Azure Web App or another Azure service prepared to host your ASP.NET Core application.
  • An Azure DevOps account and access to a project that contains your ASP.NET Core application.
  • Adequate permissions to create service connections in Azure DevOps and to deploy resources in Azure.
Creating a Service Connection: The Process

The path to a seamless deployment experience starts in the Azure DevOps portal, where you’ll configure a link to your Azure resources.

Step 1: Access Your Project Settings

Log into Azure DevOps and navigate to your project dashboard. Find and click on “Project settings” at the bottom left.

Step 2: Initiate Service Connection Setup

In the settings menu, select “Service connections” under the “Pipelines” category. Here, you manage integrations with external services. Click “New service connection” and choose “Azure Resource Manager” as the type.

Step 3: Authentication and Configuration

Choose “Service principal (automatic)” for authentication, which automatically generates a service principal for secure communication between Azure DevOps and Azure.

Configure the connection scope to the resource group level to tightly integrate with the resources used by your application.

  • Subscription: Pick the Azure subscription hosting your app.
  • Resource Group: Select the group containing your Azure Web App.
  • Service Connection Name: Name it descriptively, e.g., “ASPNetCoreDeployment.”
  • Description: Optionally, describe the connection for easier identification.

Save your configuration to create the new service connection.

Validation and Usage

With the service connection in place, validate it by deploying a simple update to your ASP.NET Core application. Below is an example Azure Pipelines YAML configuration that demonstrates how to use the service connection for deployment.

Example azure-pipelines.yml:
trigger:
- main

pool:
vmImage: 'ubuntu-latest'

variables:
buildConfiguration: 'Release'

steps:
- task: UseDotNet@2
inputs:
packageType: 'sdk'
version: '6.x'
installationPath: $(Agent.ToolsDirectory)/dotnet

- script: dotnet build --configuration $(buildConfiguration)
displayName: 'Build project'

- script: dotnet publish --configuration $(buildConfiguration) --output $(Build.ArtifactStagingDirectory)
displayName: 'Publish project'

- task: AzureWebApp@1
inputs:
azureSubscription: 'ASPNetCoreDeployment'
appName: '<Your-Azure-Web-App-Name>'
package: '$(Build.ArtifactStagingDirectory)'

Replace <Your-Azure-Web-App-Name> with the name of your Azure Web App. This pipeline triggers on commits to the main branch, builds the ASP.NET Core project using .NET 6, publishes the output, and then deploys it to the specified Azure Web App using the service connection you created.

Conclusion

Establishing a service connection in Azure DevOps is a critical step in automating the deployment of ASP.NET Core applications. This guide has walked you through creating a service connection, validating it, and utilizing it in your deployment pipeline. By following these steps, developers can streamline their workflows, ensuring that ASP.NET Core applications are deployed efficiently and securely from Azure DevOps to Azure.

Reference:

Image source: https://pixabay.com/illustrations/network-rectangle-rings-networking-1989138/

Published by Allan Mangune

I hold the esteemed qualification of a Certified Public Accountant and have earned a Master's degree in Science with a specialization in Computer Information Systems. Since entering the realm of software development in 2000, my focus has been on adopting secure coding practices, an endeavour I have intensified after receiving my Certified Ethical Hacker v5 certification in 2008. My professional journey includes guiding clients through their digital transformation journey, particularly emphasizing digital security issues. For more than ten years, I have provided Agile Project Management training to well-known companies. I am a Certified ScrumMaster and have completed the Prince2 Agile Foundation certification. I had the privilege of being recognized as a Microsoft MVP for ASP.NET for ten consecutive years. Previously, I also served as a Microsoft Certified Trainer. As a hobby, I enjoy assembling personal unmanned aerial vehicles during my downtime.

Leave a comment