Problem:

Azure Image Builder (AIB) is an image automation solution in Azure that’s built on top of HashiCorp Packer. While the solution works great when your scripts run without any errors, getting to that point can be challenging. Microsoft’s documentation states you should run your code interactively against a test virtual machine. However, sometimes unforeseen issues can still arise during an image build. Troubleshooting issues requires you to download the Packer log from the storage account in your staging resource group. Parsing the log is not fun but I have a solution to help cut down on the noise.

Solution:

  1. Download the log file from the storage account in the staging resource group.
  2. Open the log file in Visual Studio Code.
  3. Press “CTRL + H” on your keyboard to open the Replace window.
  1. Click on the Regular Expressions button to the right of the Find input “.*“.
  1. Paste the following text in the Find input: ^\[[a-z0-9-]{36}\] PACKER ERR .*$\n
  1. Click the Replace All button.

Explanation:

The Packer logs that are output to the storage account in the staging resource group have a bunch of noise. The noise events are events that highlight the creation and removal of your build resources. Most of the time that information is not important since most errors are caused by your scripts or in AIB terms, your customizers. The events that are noise have a similar pattern. They are prefixed by a GUID surrounded in square brackets and followed by “PACKER ERR”. So, I keyed off that and selected everything else in the line, to include the new line. When you click the Replace All button, the only events left are the events prefixed with “PACKER OUT”. Any output from your scripts will be seen in these remaining events.