Automating Builds with Triggered and Multi-Step Tasks
This lesson explains the triggers that run saved ACR tasks, how base image triggers patch images automatically, and how multi-step YAML tasks build, test and push.
Learning outcomes
After completing this lesson, you will be able to:
- Describe the four task triggers and their defaults.
- Explain how base image triggers rebuild dependent images.
- Describe the build, push and cmd step types.
- Choose between quick, triggered and multi-step tasks.
Saved tasks and their triggers
A quick task runs once. A task created with az acr task create is a saved resource in the registry that holds a build definition and one or more triggers. Each time a trigger fires, the task runs and its run is recorded. Tasks can also be run manually with az acr task run.
Four kinds of trigger are available, and a single task can combine them.
- Source code commit: a webhook on a GitHub or Azure Repos repository starts the task when code is pushed. It is enabled by default when the context is a Git repository, and it needs a personal access token so that ACR can create the webhook.
- Pull request: starts the task when a pull request is opened or updated. It is disabled by default.
- Base image update: starts the task when the base image named in the Dockerfile's
FROMline is updated in the same registry, another ACR, or a public registry. - Timer: starts the task on a cron schedule in UTC, for example nightly rebuilds or clean-up jobs.
Task triggers
Automatic patching with base image triggers
Security fixes for operating system packages and language runtimes arrive in base images. Without automation, every application image built on a patched base remains vulnerable until someone remembers to rebuild it. ACR Tasks tracks the base image dependency of each task it builds: when it builds an image, it records the base image's digest, and when that base image is updated, it queues a rebuild of every dependent image.
A common design keeps a curated base image, such as contoso.azurecr.io/base/python:3.12, imported from Microsoft Artifact Registry and patched centrally. Application tasks reference it in their FROM line. When the platform team updates the base, every application image is rebuilt with a new unique tag, ready for deployment through the normal release process.
-
Create the base image task
A task builds or imports the curated base image and pushes it with a stable tag.
-
Create application tasks
Each application task's Dockerfile uses
FROM REGISTRY.azurecr.io/base/python:3.12, and the base image trigger is enabled. -
Update the base
The platform team pushes a patched base image with the same stable tag.
-
Rebuild automatically
ACR detects the new base digest and runs every dependent application task, producing new images.
The following command creates a task that builds from a GitHub repository, with both commit and base image triggers. The token is a GitHub personal access token with repository access.
az acr task create --registry REGISTRY --name build-orders-api \
--image "orders-api:{{.Run.ID}}" \
--context https://github.com/contoso/orders-api.git#main \
--file Dockerfile --git-access-token GITHUB_TOKEN \
--base-image-trigger-enabled true --commit-trigger-enabled trueThe following diagram shows how one base image update rebuilds every service image.

How a base image update spreads
Multi-step tasks
Many builds need more than one step: build the image, run its unit tests inside it, push it only if the tests pass, and perhaps build a second image. A multi-step task describes these steps in a YAML file, usually named acr-task.yaml, and runs them in order or in parallel. Each step is one of three types.
| Step type | What it does | Example |
|---|---|---|
| build | Builds an image with Docker build syntax | build: -t $Registry/api:$ID -f Dockerfile . |
| push | Pushes one or more built images | push: ["$Registry/api:$ID"] |
| cmd | Runs a container as a step, such as a test runner or a CLI | cmd: $Registry/api:$ID python -m pytest |
The following file builds an API image, runs its tests in the image, and pushes the image only if the test step succeeds. $Registry and $ID are aliases for the registry login server and the run ID.
version: v1.1.0
steps:
- id: build
build: -t $Registry/orders-api:$ID -f Dockerfile .
- id: test
cmd: $Registry/orders-api:$ID python -m pytest -q
when: ["build"]
- id: push
push:
- $Registry/orders-api:$ID
when: ["test"]The when property sets dependencies, so steps without dependencies on each other can run in parallel. A step that fails stops the task, which is what keeps untested images out of the registry. The file is run with az acr run --file acr-task.yaml . or saved as a task with az acr task create --file acr-task.yaml.
Build, push or cmd?
Choosing the right kind of task
The same build can be expressed in several ways, and exam scenarios usually describe the trigger or the workflow that decides the choice.
Quick, triggered or multi-step?
Patching dozens of images automatically
An organization runs 35 Python microservices, all built on a shared base image in its registry. Last month a critical OpenSSL fix took two weeks to reach production because each team rebuilt manually. The organization wants every service image rebuilt within minutes of a base image update, with tests run before any new image is pushed.
Each service should have a saved ACR task defined by a multi-step YAML file that builds, tests and then pushes, with the base image trigger enabled. When the platform team pushes the patched base, ACR detects the change and runs all 35 tasks; an image is pushed only when its tests pass, with a unique tag from the run ID. Deployment pipelines can then pick up the new tags.
A timer trigger would rebuild nightly whether or not the base changed, and could still leave a gap of up to a day. A quick task in each team's pipeline would still depend on someone starting it. A commit trigger fires only when the application code changes, not when the base image does.
Which ACR task trigger is enabled by default for a Git context, and which is disabled by default?
Show answer
The source code commit trigger is enabled by default; the pull request trigger is disabled by default. Base image and timer triggers are configured as needed.
Exam Tips
Remember for the exam
- Commit triggers are on by default for Git contexts; pull request triggers are off.
- Base image triggers rebuild dependent images when the FROM image is updated.
- Multi-step YAML has build, push and cmd steps; when sets dependencies.
- Timer triggers use cron schedules in UTC.