Introduction

Azure Image Builder creates custom VM images from source images with customizations. When the build pipeline fails, you can't create or update your custom images, blocking deployments that depend on specific configurations.

Symptoms

Build failed:

```bash $ az image builder run --name my-image-template --resource-group my-rg

Build failed: Customization step 'Shell' failed with exit code 1 ```

VM provisioning timeout:

json
{
  "provisioningState": "Failed",
  "error": {
    "code": "ProvisioningTimeout",
    "message": "VM provisioning timed out after 60 minutes"
  }
}

Customization error:

bash
# In build logs:
[ERROR] Customization script failed at line 42: apt-get install -y nonexistent-package
E: Unable to locate package nonexistent-package

Common Causes

  1. 1.Customization script error - Shell or PowerShell script fails
  2. 2.Package installation failure - Package not found or version conflict
  3. 3.Network connectivity issues - Can't reach package repositories
  4. 4.VM size too small - Insufficient resources for customization
  5. 5.Timeout exceeded - Build takes too long
  6. 6.Source image issues - Invalid or unavailable source image
  7. 7.Permission issues - Identity lacks required permissions

Step-by-Step Fix

  1. 1.Check logs for specific error messages
  2. 2.Verify configuration settings
  3. 3.Test network connectivity
  4. 4.Review recent changes
  5. 5.Apply corrective action
  6. 6.Verify the fix

Step 1: Check Build Status and Logs

```bash # Get image template status az image builder show \ --name my-image-template \ --resource-group my-rg \ --query '{LastRun:lastRunStatus,ProvisioningState:provisioningState}'

# Get detailed run logs az image builder run list \ --name my-image-template \ --resource-group my-rg \ --query '[0]' ```

Step 2: Download Build Logs

```bash # Get build logs from storage account # Find the staging resource group created by Image Builder az group list --query "[?contains(name, 'IT_')].name" -o tsv

# Navigate to logs in storage account # Azure Portal > Resource Group > IT_* > Storage Account > container > logs ```

Step 3: Check Customization Script

```bash # Review shell script for errors cat customization.sh

# Test script locally before using in template bash -n customization.sh # Syntax check bash -x customization.sh # Run with debug ```

Step 4: Verify Source Image

```bash # Check source image exists az image show \ --name source-image \ --resource-group my-rg \ --query '{Publisher:storageProfile.osDisk.osType,Version:storageProfile.imageReference.version}'

# Or check marketplace image az vm image show \ --publisher Canonical \ --offer UbuntuServer \ --sku 18.04-LTS \ --version latest ```

Step 5: Increase Build Timeout

```bash # Update template with longer timeout az image builder template update \ --name my-image-template \ --resource-group my-rg \ --build-timeout-in-minutes 120

# Default is 60 minutes, max is 240 ```

Step 6: Fix Package Installation Issues

```bash # In customization script, use package installation best practices

# BAD: Assume package exists apt-get install -y mypackage

# GOOD: Check and handle failure apt-get update || exit 1 apt-get install -y mypackage || { echo "Failed to install mypackage, trying alternative..." apt-get install -y alternative-package || exit 1 }

# Use version pinning to avoid conflicts apt-get install -y nginx=1.18.0-0ubuntu1 ```

Step 7: Configure Network Access

```bash # If VM needs to access internet, ensure VNet allows outbound traffic # For private environments, configure private endpoints

# Add VNet configuration to template az image builder template create \ --name my-image-template \ --resource-group my-rg \ --image-source /subscriptions/SUB/resourceGroups/my-rg/providers/Microsoft.Compute/images/source-image \ --build-rg-name IT_customimages \ --vnet /subscriptions/SUB/resourceGroups/my-rg/providers/Microsoft.Network/virtualNetworks/my-vnet \ --subnet default \ --os-type Linux \ --customization-script customization.sh ```

Step 8: Increase VM Size

```bash # Use larger VM for build if customization is resource-intensive az image builder template update \ --name my-image-template \ --resource-group my-rg \ --vm-size Standard_D4s_v3 # More CPU and RAM

# Default: Standard_D1_v2 (1 vCPU, 3.5 GB RAM) # Recommended for heavy customization: Standard_D4s_v3 or larger ```

Step 9: Check Managed Identity Permissions

```bash # Image Builder uses managed identity to access resources # Ensure identity has required permissions

# Get identity az image builder template show \ --name my-image-template \ --resource-group my-rg \ --query identity.userAssignedIdentities

# Assign required roles az role assignment create \ --assignee OBJECT_ID \ --role Contributor \ --scope /subscriptions/SUB/resourceGroups/my-rg

# For image distribution: az role assignment create \ --assignee OBJECT_ID \ --role "Managed Image Operator" \ --scope /subscriptions/SUB/resourceGroups/target-rg ```

Step 10: Test with Minimal Customization

```bash # Create simple test template to isolate issues az image builder template create \ --name test-template \ --resource-group my-rg \ --image-source Canonical:UbuntuServer:18.04-LTS:latest \ --build-rg-name IT_test \ --os-type Linux \ --customization-script 'echo "Hello World" > /tmp/test.txt' \ --dist-type SharedImage \ --dist-rg-name my-rg \ --dist-gallery-name my-gallery \ --dist-image-name test-image

# Run test az image builder run --name test-template --resource-group my-rg

# If this works, add customizations one at a time to find the issue ```

Image Builder Troubleshooting Checklist

CheckToolFix
Build statusAzure PortalView logs
Script syntaxbash -nFix errors
Package availabilityapt-cache searchUpdate packages
Network accessVNet flow logsAllow outbound
VM sizeAzure PortalIncrease size
Permissionsaz role assignmentAdd roles

Verification

```bash # After fixing, run build again az image builder run \ --name my-image-template \ --resource-group my-rg \ --query '{Status:lastRunStatus.state,Image:lastRunStatus.imageVersion}'

# Should show "Succeeded" and image version

# Verify image created az image show \ --name my-custom-image \ --resource-group my-rg \ --query '{Name:name,ProvisioningState:provisioningState}' ```

  • [Fix Azure VM Extension Failed](/articles/fix-azure-vm-extension-failed)
  • [Fix Azure VM Not Starting](/articles/fix-azure-vm-not-starting)
  • [Fix Azure Shared Image Gallery Replication Slow](/articles/fix-azure-shared-image-gallery-replication-slow)
  • [Technical troubleshooting: Fix Azure Aks Pod Crashloopbackoff Issue in Azure](azure-aks-pod-crashloopbackoff)
  • [Technical troubleshooting: Fix Azure Api Management Policy Expression Runtime](azure-api-management-policy-expression-runtime-error)
  • [Technical troubleshooting: Fix Azure App Configuration Feature Flag Not Refre](azure-app-configuration-feature-flag-not-refreshing)
  • [Technical troubleshooting: Fix Azure App Service 503 Always On Disabled Issue](azure-app-service-503-always-on-disabled)
  • [Technical troubleshooting: Fix Azure Application Gateway Err SSL Unrecognized](azure-application-gateway-err-ssl-unrecognized-name-alert)

<script type="application/ld+json"> { "@context": "https://schema.org", "@type": "TechArticle", "headline": "Fix Azure Image Builder Pipeline Failed", "description": "Troubleshoot Azure Image Builder pipeline failures. Check build logs, VM configuration, and customization scripts.", "url": "https://www.fixwikihub.com/fix-azure-image-builder-pipeline-failed", "publisher": { "@type": "Organization", "name": "FixWikiHub", "url": "https://www.fixwikihub.com" }, "author": { "@type": "Person", "name": "FixWikiHub Editorial Team" }, "datePublished": "2026-04-02T20:33:35.309Z", "dateModified": "2026-04-02T20:33:35.309Z" } </script>