Pipelines: design and implement deployments · Topic 3 of 3
Deploying Containers, Binaries, Scripts and Databases
AZ-400 deployment mechanics: container images to ACR, AKS and App Service, binary packages, Azure CLI scripts, and database changes with DACPAC.
- 5 min
- Build once, push to ACR, tag uniquely, scan, then deploy. Let the target pull with managed identity and the AcrPull role.
- AKS:
KubernetesManifest@1orHelmDeploy@0. App Service:AzureWebApp@1orAzureWebAppContainer@1. - Scripts use
AzureCLI@2orAzurePowerShell@5with a service connection and should be idempotent.
What it is
After the strategy is chosen, something has to put the application on the target. This topic covers the three common forms: containers (an image pushed to a registry and run on a platform), binaries (a package or zip deployed to a host) and scripts (Azure CLI, PowerShell or Bash that do the work), plus the special case of deploying database changes.
How it works
Containers
- Build the image and push it to a registry such as Azure Container Registry (ACR).
- Tag it with something unique, such as the build ID or commit SHA.
- Scan the image for vulnerabilities before deploying.
- Deploy to a runtime that pulls the image by tag or digest.
| Target | Common deployment approach |
|---|---|
| Azure Kubernetes Service (AKS) | KubernetesManifest@1 applies manifests (it supports canary strategies), or HelmDeploy@0 installs a Helm chart |
| Azure Container Apps | The Azure Container Apps deploy task or az containerapp update |
| App Service (containers) | AzureWebAppContainer@1 points the app at a new image tag |
| Azure Container Instances | az container create for short lived or simple workloads |
Build and push with Docker@2 (the buildAndPush command), or let ACR build the image in the cloud (az acr build), which avoids needing Docker on the agent. Let the target pull with a managed identity that has the AcrPull role, instead of a registry password. In GitHub Actions the equivalents are the docker/build-push-action, azure/k8s-deploy and azure/webapps-deploy actions.
- task: Docker@2
inputs:
containerRegistry: my-acr-connection
repository: shop/web
command: buildAndPush
tags: |
$(Build.BuildId)
Binaries and packages
For classic application hosting, you build once, publish the result as an artifact, and deploy that same artifact to each environment.
| Target | Approach |
|---|---|
| App Service | AzureWebApp@1 deploys a zip or package. Run from package mounts the zip read only |
| Virtual machines | A deployment job targeting an environment with VM resources, running scripts or tasks on each machine. Classic deployment groups do the same in classic releases |
| IIS | Web Deploy or scripted deployment |
| Azure Functions | AzureFunctionApp@2 |
Publish with PublishPipelineArtifact@1 and download with the download step in later jobs and stages, so every environment receives the identical bits.
Scripts
Scripts cover anything without a dedicated task.
| Task | Use |
|---|---|
AzureCLI@2 | Run Azure CLI commands authenticated through a service connection |
AzurePowerShell@5 | Run Az PowerShell commands the same way |
Bash@3 / PowerShell@2 | General scripts |
SSH@0 | Run commands on a remote Linux host |
Good deployment scripts are idempotent, take their settings as parameters or environment variables, exit with a non zero code on failure (so the step fails) and never print secrets.
Database deployments
Application code can be replaced. Data cannot. Database changes need extra care.
| Approach | How it works |
|---|---|
| State based (DACPAC) | Compare the desired schema in a DACPAC to the target and generate the changes. Deploy with SqlAzureDacpacDeployment@1 or sqlpackage. A deploy report previews what would change. BlockOnPossibleDataLoss stops risky changes by default |
| Migration based | Ordered, versioned scripts that move the schema forward: Entity Framework Core migrations (dotnet ef migrations script --idempotent), Flyway or Liquibase. Each runs once and is recorded |
Safe practices:
- Use expand and contract: first add the new column or table in a change that works with the old and the new code, deploy the code, then remove the old structure in a later release. This makes rollback possible.
- Run schema changes as a separate stage with an approval, before the application stage, and test them on a copy of production data first.
- Give the pipeline identity least privilege and prefer Microsoft Entra authentication to SQL passwords.
- Back up or snapshot before destructive changes, and prefer roll forward because data written by the new version may not fit the old schema.
A worked scenario
A team ships a web API as a container and a SQL database. The pipeline builds the image once with Docker@2, tags it with $(Build.BuildId), scans it, and pushes it to ACR. A migration stage runs an idempotent EF Core script against staging, then production after approval. A deploy stage updates the AKS manifest with the new tag, using a canary step. The column rename the developers wanted is split into add column, then move data, then drop column in a later release.
What to remember for the exam
- Build once, push to ACR, tag uniquely, scan, then deploy. Let the target pull with managed identity and the AcrPull role.
- AKS:
KubernetesManifest@1orHelmDeploy@0. App Service:AzureWebApp@1orAzureWebAppContainer@1. - Scripts use
AzureCLI@2orAzurePowerShell@5with a service connection and should be idempotent. - Database: DACPAC (state based) or migrations (versioned scripts). Use expand and contract. Roll forward over rollback.
- Publish an artifact once and download it in each stage.
A database column rename is never one step in a zero downtime design. It is add, copy, switch, then remove.
How the exam asks about this
- "Deploy a Helm chart to AKS from a pipeline."
HelmDeploy@0. - "Run Azure CLI commands in a pipeline using a service connection."
AzureCLI@2. - "Apply schema changes without risking data loss." A DACPAC with a deploy report and data loss blocking, or reviewed migrations.
- "Let App Service pull from a private registry without passwords." Managed identity with AcrPull.
Common mistakes
Rebuilding per environment. The tested artifact is not the deployed one.
Using the latest tag. It hides what is running.
Dropping columns in the same release. The old code still needs them during a rollback.
Giving the pipeline owner rights on the database. Use the least privilege that works.
Check yourself
Which role lets a managed identity pull images from ACR?
AcrPull.
What is the name of the pattern that adds a new schema element first and removes the old one later?
Expand and contract.
Which task runs Azure CLI commands through an Azure service connection?
AzureCLI@2.
Topic 3 of 3 in Pipelines: design and implement deployments
Test yourself on Pipelines: design and implement deployments
The full Microsoft AZ-400 question bank has 766 questions, with timed practice exams and an explanation for every answer.
This study guide is independent and is not affiliated with, endorsed by, or sponsored by Microsoft. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.