AEM Cloud Manager build failure due to detached HEAD in custom validation

✨ This content is AI generated and could be inaccurate. Generative AI Terms

This article describes how to address build failures in Adobe Experience Manager Cloud Manager pipelines when custom validation steps fail due to the repository being in a detached HEAD state.

Description description

Environment

  • Adobe Experience Manager (AEM) as a Cloud Service (all versions)

Symptoms

A Cloud Manager pipeline build fails during a custom validation step in a module. The error occurs when the custom validation attempts to determine the current Git branch, but the repository is in a detached HEAD state, which is standard in Cloud Manager builds.

The following error appears in the build logs:

java.lang.IllegalStateException: Unable to determine current Git branch. Repository is in detached HEAD state.

The build log also shows commands indicating a shallow checkout and detached HEAD state:

git fetch --depth 1 origin <commit-hash>
git checkout FETCH_HEAD
You are in 'detached HEAD' state.

This issue occurs on every pipeline run in Cloud Manager when the custom validation expects branch information and Git history.

Cause

The custom validation step fails because it expects Git branch information and history, which are not available in Cloud Manager’s shallow, detached HEAD checkouts.

Resolution resolution

Follow the steps below to resolve the issue:

  1. Modify the custom validation logic to detect when it is running in Cloud Manager by checking for the CM_BUILD=true environment variable.
  2. When CM_BUILD=true is set, skip the validation logic that requires branch information or Git history.
  3. Alternatively, update the validation to handle detached HEAD states gracefully and exit without failing the build when branch information is unavailable.
  4. Test the build locally with CM_BUILD=true set to confirm that the custom validation is skipped or handled correctly.
  5. Commit the updated validation logic to the repository and push the changes.
  6. Trigger a new pipeline execution in Cloud Manager.
  7. Verify that the build passes the custom validation step.
recommendation-more-help
experience-cloud-kcs-help-kbarticles