Deploy to Azure Container Registry
In this how-to guide, you will learn how to configure CircleCI to deploy to Azure Container Registry.
Introduction
This page describes a simple deployment to the Azure Container Registry (ACR) using the CircleCI ACR orb and version 2.1 configuration.
| To take advantage of secrets masking, it is best practice to set environment variables at the project level or within a context. |
In addition to the orb described below, CircleCI has created an Azure convenience image focusing on deployment: cimg/azure.
For detailed information about the Azure ACR orb, including all options, refer to the CircleCI ACR Orb Reference page.
1. Provide environment variables to CircleCI
Whether your require a user or service principal login, you will need to provide environment variables for username, password and tenant to CircleCI. For user logins use environment variable names as follows:
-
AZURE_USERNAME -
AZURE_PASSWORD -
AZURE_TENANT
For service principal logins use:
-
AZURE_SP -
AZURE_SP_PASSWORD -
AZURE_SP_TENANT
2. Deploy to ACR
Use the orb’s build-and-push-image job to build your image and deploy it to ACR. Note the use of workflows to deploy only if the current branch is main.
| Make sure to replace any placeholder versions in the example. |
version: 2.1 # Use version 2.1 config to get access to orbs, pipelines
orbs:
azure-acr: circleci/azure-acr@0.2.2 # Use the Azure ACR orb in your config
workflows:
build-deploy:
jobs:
- azure-acr/build-and-push-image:
dockerfile: <name-of-your-dockerfile> # defaults to `Dockerfile`
path: <path-to-your-dockerfile> # Defaults to working directory
login-server-name: <your-login-server-name> # e.g. {yourregistryname}.azure.io
registry-name: <your-ACR-registry-name>
repo: <URI-to-your-login-server-name>
filters:
branches:
only: main # Only deploys when the commit is on the `main` branch
If pushing to your repository is required, see the Users, Organizations, and Integrations Guide. Then, configure the Azure Web App to use your production branch.
Track your deployments with deploy markers
Deploy markers provide a way to track and manage your Azure Container Registry deployments in the CircleCI web app. When you add deploy markers to your deployment job, you can view a timeline of all deployments, track their status, and enable rollback and deploy pipelines.
You have two options for setting up deploy markers:
-
In-app setup: Use the guided setup in the CircleCI web app when configuring a Rollback Pipeline or Deploy Pipeline. The setup will walk you through adding deploy markers to your configuration. If you are using GitHub and have the CircleCI GitHub App installed, you can use AI to generate the deploy marker configuration automatically.
-
Manual setup: Add deploy marker commands directly to your
.circleci/config.ymlfile by following the Configure Deploy Markers guide.
Both approaches will enable you to track deployment history and manage rollbacks directly from the CircleCI web app.