Implementing Hybrid Pipelines and VM Templates
This lesson explains pipelines that cross networks, and how to build machine images.
Learning outcomes
After completing this lesson, you will be able to:
- Design a hybrid pipeline with several pools.
- Describe VM resources in environments.
- Explain how golden images are built and stored.
- Identify controls for self-hosted machines.
Hybrid pipelines
A hybrid pipeline delivers to more than one kind of location, such as on-premises servers and Azure. The usual design separates work by location. Build and test stages run on hosted agents, as they need no private access. A deployment stage for on-premises systems runs on a self-hosted agent inside the private network, and a stage for Azure runs on a hosted agent, using a service connection.
stages:
- stage: Build
pool:
vmImage: ubuntu-latest
jobs:
- job: Compile
steps:
- script: ./build.sh
- publish: out
artifact: app
- stage: DeployOnPrem
dependsOn: Build
pool:
name: datacentre-pool
jobs:
- deployment: Web
environment: onprem-production
strategy:
runOnce:
deploy:
steps:
- script: ./install.sh
- stage: DeployAzure
dependsOn: Build
pool:
vmImage: ubuntu-latest
jobs:
- deployment: Web
environment: azure-production
strategy:
runOnce:
deploy:
steps:
- script: ./deploy-azure.shA job in one stage can therefore run in a different network from a job in the next stage, with the artifact as the only thing connecting them. Azure Pipelines also has VM resources in environments: an agent installed on each target server registers it with the environment, and a deployment job can then target those machines by name or tag. Azure Arc and Azure Machine Configuration can extend management to these servers.
Designing a hybrid pipeline
Virtual machine templates
A VM template, or golden image, is a prepared machine image containing an operating system, patches and installed software. Pipelines that build images turn a manual process into repeatable automation. New virtual machines then start in a known state, and they scale faster, since nothing needs to be installed at start-up.
Azure VM Image Builder
Azure VM Image Builder is a managed service built on HashiCorp Packer. You define a template containing the source image, customization steps and distribution targets. It builds in a temporary resource group and removes it afterwards.
Packer
HashiCorp Packer is a standalone tool with templates written in HCL. It works across clouds, and it runs directly in a pipeline.
Azure Compute Gallery
Azure Compute Gallery stores and versions images, replicates them between regions, and shares them with other subscriptions. Virtual machines and scale sets refer to a gallery image, and latest or an explicit version can be used.
A typical image pipeline runs on a schedule, such as monthly, so that patches are included. The following sequence shows the stages.
-
Build
Start from a marketplace or existing image, and apply patches and software with Image Builder or Packer.
-
Test
Create a test virtual machine from the image, and run verification and security scans.
-
Publish
Add a new image version to Azure Compute Gallery, and replicate it to the required regions.
-
Roll out
Update scale sets or agent pools to the new version, in stages.
The same technique underlies custom images for self-hosted agents and Managed DevOps Pools.
The following diagram shows a golden image pipeline that keeps a scale set's VM image up to date.

An image pipeline
Securing self-hosted machines
A self-hosted agent runs code from pipelines, so it is an attractive target. The following measures reduce the risk.
- Run the agent under a low-privilege account, not as an administrator.
- Separate pools by trust level, so production deployments do not share machines with pull request builds.
- Use ephemeral machines, so that nothing persists between jobs.
- Limit the network paths that an agent can reach, using network security groups and firewall rules.
- Set pipeline permissions on the agent pool, so that only selected pipelines can use it.
The GitHub equivalent of the last point is a runner group with access limited to selected repositories, and even selected workflows.
Hardening self-hosted agents
A slow scale-out
A web tier on a virtual machine scale set takes 25 minutes to serve traffic after scaling out, because each instance installs software at start-up. Instances also vary, as package versions change over time. What should you recommend?
You should build a golden image with Azure VM Image Builder or Packer through a scheduled pipeline, store versions in Azure Compute Gallery, and use a version in the scale set. Software is then already present, so scale-out is much faster, and all instances are the same. A larger virtual machine size would shorten the install slightly, but the drift would remain. Moving the install to a custom script at a different time does not remove it.
What does Azure Compute Gallery add to a golden image process?
Show answer
It stores image versions, replicates them across regions and shares them with other subscriptions.
Exam Tips
Remember for the exam
- Hybrid pipelines run stages on different pools, with the artifact connecting them.
- VM resources in environments target machines through an installed agent.
- Azure VM Image Builder is a managed service built on Packer.
- Azure Compute Gallery versions and replicates images.
- Separate production agents from pull request agents.