Uploaded image for project: 'Bamboo Data Center'
  1. Bamboo Data Center
  2. BAM-14600

Retried checkout of a git repository can leave it in a detached HEAD state causing Maven releases to fail

XMLWordPrintable

      Bamboo's source checkout task comes with a built-in retry mechanism which is obviously very nice to work around e.g. network issues.

      But it seems that a retry leaves a git repository in a 'detached HEAD' state, probably because it is checking out a particular commit hash instead of the configured branch. The following logs describes the situation:

      simple	07-May-2014 04:47:18	Starting task 'Checkout Repository greenhopper' of type 'com.atlassian.bamboo.plugins.vcs:task.vcs.checkout'
      ...
      simple	07-May-2014 04:47:18	Fetching 'refs/heads/master' from 'https://stash.atlassian.com/scm/jag/jira-agile.git'. Will try to do a shallow fetch.
      simple	07-May-2014 04:47:19	From https://stash.atlassian.com/scm/jag/jira-agile
      simple	07-May-2014 04:47:19	 * [new branch]      master     -> master
      simple	07-May-2014 04:47:19	Checking out revision 68476d668e8ec9af983a4e02835c1cdb99f97db3.
      simple	07-May-2014 04:47:19	fatal: reference is not a tree: 68476d668e8ec9af983a4e02835c1cdb99f97db3
      error	07-May-2014 04:47:19	Checkout to revision 68476d668e8ec9af983a4e02835c1cdb99f97db3 has failed.
      simple	07-May-2014 04:47:20	Warning: failed to checkout source code to directory '/opt/bamboo-agent/xml-data/build-dir/GH-DEVPIPELINE-RELEASE/artifact', trying to recover...
      simple	07-May-2014 04:47:20	Cleaned source directory '/opt/bamboo-agent/xml-data/build-dir/GH-DEVPIPELINE-RELEASE/artifact'...
      ...
      simple	07-May-2014 04:47:20	Fetching 'refs/heads/master' from 'https://stash.atlassian.com/scm/jag/jira-agile.git'.
      simple	07-May-2014 04:47:51	From https://stash.atlassian.com/scm/jag/jira-agile
      simple	07-May-2014 04:47:51	 * [new branch]      master     -> master
      simple	07-May-2014 04:47:51	From https://stash.atlassian.com/scm/jag/jira-agile
      ...
      simple	07-May-2014 04:47:52	 * [new tag]         jira-greenhopper-plugin-6.4.5-RC1 -> jira-greenhopper-plugin-6.4.5-RC1
      simple	07-May-2014 04:47:52	Fetching to source directory '/opt/bamboo-agent/xml-data/build-dir/GH-DEVPIPELINE-RELEASE/artifact' completed, proceeding with checkout...
      simple	07-May-2014 04:47:52	Checking out revision 68476d668e8ec9af983a4e02835c1cdb99f97db3.
      simple	07-May-2014 04:47:52	Note: checking out '68476d668e8ec9af983a4e02835c1cdb99f97db3'.
      simple	07-May-2014 04:47:52	
      simple	07-May-2014 04:47:52	You are in 'detached HEAD' state. You can look around, make experimental
      simple	07-May-2014 04:47:52	changes and commit them, and you can discard any commits you make in this
      simple	07-May-2014 04:47:52	state without impacting any branches by performing another checkout.
      simple	07-May-2014 04:47:52	
      simple	07-May-2014 04:47:52	If you want to create a new branch to retain commits you create, you may
      simple	07-May-2014 04:47:52	do so (now or later) by using -b with the checkout command again. Example:
      simple	07-May-2014 04:47:52	
      simple	07-May-2014 04:47:52	  git checkout -b new_branch_name
      simple	07-May-2014 04:47:52	
      simple	07-May-2014 04:47:52	HEAD is now at 68476d6... Merge branch 'master' of ssh://stash.atlassian.com:7997/jag/jira-agile
      simple	07-May-2014 04:47:52	Checkout completed, recover successful.
      simple	07-May-2014 04:47:52	Updated source code to revision: 68476d668e8ec9af983a4e02835c1cdb99f97db3
      simple	07-May-2014 04:47:52	Finished task 'Checkout Repository greenhopper'
      

      Normally this is not a big problem. But when trying to do a release with Maven, one of the actions is to commit the usual Maven version bump and push the commits back upstream. But in a 'detached HEAD' situation, there is no branch to commit back. Hence the release fails:

      build	07-May-2014 04:59:37	[INFO] Executing: /bin/sh -c cd /opt/bamboo-agent/xml-data/build-dir/GH-DEVPIPELINE-RELEASE/artifact && git commit --verbose -F /tmp/maven-scm-129526871.commit pom.xml greenhopper-api/pom.xml greenhopper-jira-bridge-parent/pom.xml greenhopper-jira-bridge-parent/greenhopper-jira-bridge/pom.xml greenhopper-jira-bridge-parent/greenhopper-jira60-bridge/pom.xml greenhopper-jira-bridge-parent/greenhopper-jira61-bridge/pom.xml greenhopper-jira-bridge-parent/greenhopper-jira611-bridge/pom.xml greenhopper-jira-bridge-parent/greenhopper-jira62-bridge/pom.xml greenhopper/pom.xml greenhopper-client/pom.xml greenhopper-integration-test/pom.xml ondemand-acceptance-tests/pom.xml greenhopper-tpm-test/pom.xml greenhopper-tpm-test/spm/pom.xml greenhopper-performance-test/pom.xml
      build	07-May-2014 04:59:37	[INFO] Working directory: /opt/bamboo-agent/xml-data/build-dir/GH-DEVPIPELINE-RELEASE/artifact
      build	07-May-2014 04:59:37	[INFO] Executing: /bin/sh -c cd /opt/bamboo-agent/xml-data/build-dir/GH-DEVPIPELINE-RELEASE/artifact && git symbolic-ref HEAD
      build	07-May-2014 04:59:37	[INFO] Working directory: /opt/bamboo-agent/xml-data/build-dir/GH-DEVPIPELINE-RELEASE/artifact
      build	07-May-2014 04:59:37	[INFO] ------------------------------------------------------------------------
      build	07-May-2014 04:59:37	[ERROR] BUILD ERROR
      build	07-May-2014 04:59:37	[INFO] ------------------------------------------------------------------------
      build	07-May-2014 04:59:37	[INFO] An error is occurred in the checkin process: Exception while executing SCM command.
      build	07-May-2014 04:59:37	
      build	07-May-2014 04:59:37	Detecting the current branch failed: fatal: ref HEAD is not a symbolic ref
      

      I failed to reproduce this issue by triggering a retry with a dummy repository sourced on Bitbucket. But still I consider this a bug - the checkout of a given branch should never leave me in a detached state. I'm aware that there are issues when the branch has 'moved on' and the commit hash used to check out no longer references the HEAD.

      In this case the clone was done using the HTTPS protocol with the Use shallow clones options set. Would it make a difference to

      1. Uncheck the Use shallow clones option
      2. Checkout by using the ssh protocol

      ?

              Unassigned Unassigned
              mmeinhold Martin Meinhold
              Votes:
              7 Vote for this issue
              Watchers:
              20 Start watching this issue

                Created:
                Updated:
                Resolved: