There are two build pipeline yaml files that you can use to setup the build pipeline for the project.
One is for the app service and the other is for the docker image.
Add file azure-pipelines\app-service-ci.yml to the root of the project
# ASP.NET Core (.NET Framework)# Build and test ASP.NET Core projects targeting .NET9.# Add steps that publish symbols, save build artifacts, and more:# https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core# Before run pipeline please check the variables# *** General variables ***# BuildConfiguration (Release or Debug)# *** Library variables ***# azureSubscription (Only for deployment to Azure)# *** Pipeline variables ***# majorVer# minorVer# appServiceName (Only for deployment to Azure)# Changing the name the variable $(Build.BuildNumber) will change as wellname:$(majorVer).$(minorVer)$(Rev:.r)trigger:-mainpool:vmImage:ubuntu-latestvariables:-group:General-name:buildConfigurationvalue:"Release"-name:versionvalue:"$(Build.BuildNumber)"# This variable is used to update the nuget version# Single stage Build sectionsteps:-task:UseDotNet@2displayName:"Use NET9"inputs:version:"9.0.x"includePreviewVersions:true# Required for preview versions-task:NuGetAuthenticate@1displayName:"NuGet Authenticate"-task:DotNetCoreCLI@2displayName:"Build projects"inputs:command:"build"projects:"**/*.csproj"arguments:"--configuration $(BuildConfiguration)"# Update this to match your need# Run the Test (after building)-task:DotNetCoreCLI@2displayName:"Run tests"inputs:command:"test"projects:"**/*Tests/*.csproj"arguments:'--configuration $(buildConfiguration) --collect:"Code Coverage" -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=cobertura'publishTestResults:true# Publish the artifact to be ready for deploy-task:DotNetCoreCLI@2displayName:Publishinputs:command:"publish"publishWebProjects:true-task:CopyFiles@2displayName:"Copy file"inputs:targetFolder:"$(Build.ArtifactStagingDirectory)"-task:PublishBuildArtifacts@1displayName:"Publish Artifact: drop"inputs:pathToPublish:"$(Build.ArtifactStagingDirectory)"# Deploy the artifact on Azure# Please move this step to the release pipeline#- task: AzureRmWebAppDeployment@4# displayName: 'Deploy Azure App Service'# inputs:# connectionType: 'AzureRM'# azureSubscription: '$(AzureSubscription)'# appType: 'webAppLinux'# webAppName: '$(AppServiceName)'# packageForLinux: '$(System.DefaultWorkingDirectory)/**/*.zip'# runtimeStack: 'DOTNETCORE|9.0'
The Pipeline requires a Service Connections to deploy Images to Azure Container Registry.
Service Connections: AcrDevelopmentConnection
Add file azure-pipelines\app-container-ci.yml to the root of the project
# ASP.NET Core (.NET Framework)# Build and test ASP.NET Core projects targeting .NET9.# Add steps that publish symbols, save build artifacts, and more:# https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-corename:$(Build.BuildId)trigger:-mainresources:-repo:selfvariables:# Agent VM image namevmImageName:"ubuntu-latest"imageName:backend# Replace with your image nameregistry:genocs# Replace with your Docker registry (e.g., Docker Hub, ACR)repository:$(registry)/$(imageName)dockerfile:Dockerfile# Path to your DockerfilebuildArgValue:"--build-arg BUILD_ENV=$(buildEnv)"# Use this to pass the build environment to the Dockerfilestages:-stage:BuildAndPushdisplayName:BuildandPushDockerImagejobs:-job:BuilddisplayName:BuildDockerImagepool:vmImage:$(vmImageName)steps:-task:Docker@2displayName:BuildImageinputs:command:buildrepository:$(repository)tags:"$(Build.BuildId),latest"# Use build number as tagDockerfile:$(dockerfile)buildArgs:buildArgValue# Pass the the build argument# Add other build options as needed, e.g., target, context# buildContext: . # Uncomment if your Dockerfile is not in the root of the repo# target: my-target # Uncomment if you are using multi-stage builds-task:Docker@2displayName:PushImageinputs:command:pushcontainerRegistry:"AcrDevelopmentConnection"repository:$(repository)tags:"$(Build.BuildId),latest"
# ASP.NET Core (.NET Framework)# Build and test ASP.NET Core projects targeting .NET9.# Add steps that publish symbols, save build artifacts, and more:# https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core# Before run pipeline please check the variables# *** Service Connection ***# AcrConnectionDev (Service connection to Azure Container Registry for development)# AcrConnectiionUAT (Service connection to Azure Container Registry for UAT)# AcrConnectionProd (Service connection to Azure Container Registry for production)# *** General variables ***# BuildConfiguration (Release or Debug)# *** Pipeline variables ***#name:$(Build.BuildId)trigger:-noneresources:-repo:selfvariables:vmImageName:"ubuntu-latest"# Agent VM image nameimageName:fiscanner-hello# Your image namedockerfile:Dockerfile# Your Dockerfile pathcontainerArgs:"--build-arg GREETING=Souch beautifull"# Argument to pass to the containerstages:-stage:BuildAndPushdisplayName:BuildandPushDockerImagejobs:-job:DEVdisplayName:BuildDockerImagecondition:and(succeeded(),eq(variables['Build.SourceBranch'],'refs/heads/develop'),eq(variables['envName'],'dev'))pool:vmImage:$(vmImageName)steps:-task:Docker@2displayName:Buildinputs:command:buildrepository:$(imageName)tags:"$(Build.BuildId),latest"# Use build number as tagdockerfile:$(dockerfile)buildArgs:containerArgs# Pass the the build argumentcontainerRegistry:"AcrConnection2025"-task:Docker@2displayName:Pushinputs:command:pushrepository:$(imageName)tags:"$(Build.BuildId),latest"# Use build number as tagcontainerRegistry:"AcrConnection2025"