The Problem
If you’ve been experiencing issues with your custom image templates in Azure Image Builder recently, we’ve written this blog post to save you a lot of time!
Since the July Patch Tuesday, Azure Image Builder has been consistently failing during our customer deployments. We thought the initial issue was due to Windows Update provisioner within Azure Image Builder as is usually the case when the underlying Packer version has been updated.
Reviewing the Packer logs, the Packer plugin had an exit code 1 with an error exception “You cannot call a method on a null-valued expression”.
Our next step included removing any steps that include a Windows Update phase, which included the Language Pack installation, Windows Optimisations and the Windows Update script itself which resulted in a successful build!
As the same build worked last month, our next step was to build out a custom image template using the gallery image from last month. This build still failed, however, we were able to identify Windows Update worked until it tried to install the July 9, 2024 KB5040442 update.
Reviewing the known issues for this update, there was a known issue with the Windows Update Agent API while searching for Windows updates from a script.
The Solution
We’re not going to go through the steps of setting up a custom image template, we’re going to assume you already have this in place.
- Sign in to the Azure portal.
- Launch Cloud Shell and run the following command with your relevant Offer and Sku.
- Select the N – 1 or N – 2 version and copy this text to use later.
- In the search bar, enter Azure Virtual Desktop and select the service.
- Select Custom image templates, then go into your image template.
- From within your image template, expand Automation and select Export template.
- Once the template has been generated, click Add to library.
- Provide a Template name, resource group and version details and click Next.
- Under Edit template, we are going to change the version of the gallery image to deploy and update any Windows update steps to exclude Preview Windows updates and KB5040442. Search for “publisher” and within this block, change the version from “latest” to a version from May or June 2024 that we obtained from the PowerShell command earlier.
Once updated, it should look something like this.
Next search for Windows Update within the template. In our template, we had to add in the following four steps:
- avdBuiltInScript_installLanguagePacks-windowsUpdate
- avdBuiltInScript_setDefaultLanguage-windowsUpdate
- avdBuiltInScript_windowsOptimization-windowsUpdate
- avdBuiltInScript_windowsUpdate
The original will look like this:
Updated to exclude previews and KB504442.
- Click Tags and add your standard required tags.
- Click Review + Create to ensure validation passes successfully.
- Click Create.
- In the Azure Portal search base, type Templates specs, select your newly created template and click Deploy.
- All the details should be pre-populated, follow the wizard and deploy the template.
- Navigate back to the Custom image templates section within Azure Image Builder and you will now see your newly created template.
- Select your template and click Start Build.
- The build will complete successfully and when reviewing the Packer logs you will see the Windows Update skipped as it has been filtered.
Update: After several successful builds, we removed the exclusion from the final Windows Update step to install the build completed successfully with the latest cumulative update.
Hopefully, this will be addressed in the next patch cycle!