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.
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-core
name: $(Build.BuildId)
trigger:
- main
resources:
- repo: self
variables:
# Agent VM image name
vmImageName: "ubuntu-latest"
imageName: backend # Replace with your image name
registry: genocs # Replace with your Docker registry (e.g., Docker Hub, ACR)
repository: $(registry)/$(imageName)
dockerfile: Dockerfile # Path to your Dockerfile
buildArgValue: "--build-arg BUILD_ENV=$(buildEnv)" # Use this to pass the build environment to the Dockerfile
stages:
- stage: BuildAndPush
displayName: Build and Push Docker Image
jobs:
- job: Build
displayName: Build Docker Image
pool:
vmImage: $(vmImageName)
steps:
- task: Docker@2
displayName: Build Image
inputs:
command: build
repository: $(repository)
tags: "$(Build.BuildId),latest" # Use build number as tag
Dockerfile: $(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@2
displayName: Push Image
inputs:
command: push
containerRegistry: "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:
- none
resources:
- repo: self
variables:
vmImageName: "ubuntu-latest" # Agent VM image name
imageName: fiscanner-hello # Your image name
dockerfile: Dockerfile # Your Dockerfile path
containerArgs: "--build-arg GREETING=Souch beautifull" # Argument to pass to the container
stages:
- stage: BuildAndPush
displayName: Build and Push Docker Image
jobs:
- job: DEV
displayName: Build Docker Image
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/develop'), eq(variables['envName'], 'dev'))
pool:
vmImage: $(vmImageName)
steps:
- task: Docker@2
displayName: Build
inputs:
command: build
repository: $(imageName)
tags: "$(Build.BuildId),latest" # Use build number as tag
dockerfile: $(dockerfile)
buildArgs: containerArgs # Pass the the build argument
containerRegistry: "AcrConnection2025"
- task: Docker@2
displayName: Push
inputs:
command: push
repository: $(imageName)
tags: "$(Build.BuildId),latest" # Use build number as tag
containerRegistry: "AcrConnection2025"