Before you begin
-
If you haven't already, set up authentication.
Authentication verifies your identity for access to Google Cloud services and APIs. To run
code or samples from a local development environment, you can authenticate to
Compute Engine by selecting one of the following options:
-
Install the Google Cloud CLI. After installation, initialize the Google Cloud CLI by running the following command:
gcloud initIf you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
- Set a default region and zone.
-
Review logging channels
Image Builder writes logs to multiple locations to help you diagnose failures at different levels of the stack:
- Cloud Build orchestrator logs: Displays the high-level builder steps in the Cloud Build Console. If a step fails, a link to the corresponding Cloud Storage workdir directory is printed.
- Customization VM agent logs: The customization agent captures the standard output (
stdout) and standard error (stderr) of your customization steps. The orchestrator polls these records and streams them directly into the Cloud Build trace logs. If the logs are truncated or you need to inspect them in full, go to the folder matching your build ID in the_GCS_WORKDIRbucket. - Serial console logs: If the guest OS fails to boot, the customization agent can't start. In these cases, look at the serial console logs. The orchestrator streams the worker VM's serial port output directly to your Cloud Storage workdir bucket. A link to the serial log file is printed at the end of the failing Cloud Build trace.
- Guest OS journal logs: For detailed system-level troubleshooting on Linux, the customization agent uploads a full system
journallog copy to your Cloud Storage workdir bucket at the end of the run.
Resolve script failures using the debug flag
By default, if a customization step fails, Image Builder terminates execution and deletes the worker VM immediately to control costs.
To debug scripts interactively, you can enable the debug flag. This keeps the VM active, allowing you to connect directly to the active guest system by using SSH.
Enable the debug flag
In your imagebuilder.yaml file, set debug: true under the infrastructureConfig block:
infrastructureConfig: machineType: e2-standard-4 zone: us-central1-a # Enable interactive debugging debug: true instanceDurationHours: 1.5
Trigger the build and wait for failure
Submit your build using standard methods. If the pipeline encounters a script error, the following occurs:
- The orchestrator pauses the build execution.
- Image Builder does not delete the worker VM. It remains running in your project.
- The VM remains active for the time specified in the
instanceDurationHoursproperty before automatic termination.
Connect to the worker VM to debug
Look at the Cloud Build console output to retrieve the name of the active worker VM instance. Open a terminal and connect to the worker VM by using gcloud compute ssh:
gcloud compute ssh WORKER_VM_NAME \
--zone=BUILD_ZONE \
--project=PROJECT_ID
Once connected, you can run commands in real time, inspect target files, analyze running processes, review installer history logs, and test script modifications directly on the disk.
Analyze intermediate debug images
As an alternative to keeping the worker VM active with the debug flag, you can analyze the disk state by using the auto-generated debug image:
- Whenever a build fails with
debug: false(the default), the orchestrator exports the partially customized boot disk as a Compute Engine image. - The debug image is named using the pattern
image-builder-debug-image-BUILD_IDand is assigned to theimage-builder-debug-imagesimage family. To inspect the file system, create a temporary VM instance using this debug image as the boot disk:
gcloud compute instances create temp-debug-vm \ --image-family=image-builder-debug-images \ --zone=ZONE \ --project=PROJECT_IDConnect to the
temp-debug-vminstance to inspect the disk and isolate why the customization failed.