Bamboo build fails with the error fatal: not a git repository (or any of the parent directories): .git

Still need help?

The Atlassian Community is here for you.

Ask the community

Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.

Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

Summary

Builds start to fail when the Source Code Checkout throws the following exception and cannot successfully checkout code from the remote repository:

error	06-Dec-2021 01:40:50	Error occurred while running Task 'Checkout Default Repository(1)' of type com.atlassian.bamboo.plugins.vcs:task.vcs.checkout.
error	06-Dec-2021 01:40:50	java.lang.RuntimeException: com.atlassian.bamboo.plugins.stash.repository.StashRepositoryException
error	06-Dec-2021 01:40:50		at com.atlassian.bamboo.executor.RetryingTaskExecutor.rerun(RetryingTaskExecutor.java:142)
...
error	06-Dec-2021 01:40:50	Caused by: com.atlassian.bamboo.plugins.stash.repository.StashRepositoryException
error	06-Dec-2021 01:40:50		at com.atlassian.bamboo.plugins.stash.v2.BitbucketServerWorkingCopyManager.retrieveSourceCode(BitbucketServerWorkingCopyManager.java:101)
...
error	06-Dec-2021 01:40:50	Caused by: com.atlassian.bamboo.plugins.git.GitCommandException: command ['C:\Program Files\Git\cmd\git.exe' remote set-url origin file://C:\bamboo-remote-agent\Agent01\build\_git-repositories-cache\7b986fe6e7814bcab02994035eb231ff5b97044e] failed with code 128. Working directory was [C:\bamboo-remote-agent\Agent01\build\PG-JT19-JOB15]., stderr:
error	06-Dec-2021 01:40:50	fatal: not a git repository (or any of the parent directories): .git

This document does not go over the reasons why Git cache can get corrupted and how to solve them. What it does is to provide a way to workaround the problem.

Environment

This problem was initially observed in Bamboo 8.0.4 but can happen to other versions as well.

Diagnosis

There are couple of aspects that need to be verified in order to understand whether you're running into the problem described in this article. You might be running into this issue if you have one or more of the options mentioned below:

  • Check if the affected repositories have the Enable repository caching on agents option enabled.
  • Does the affected build plans have multiple Source Code Checkout tasks that run simultaneously (in parallel)?
  • Do the build plans have a Clean working directory after each build task at the end?
  • Is the Force Clean Build option checked in the Source Code Checkout task?
  • If you are running multiple remote agents in one machine, do they all share the same temporary directory? If so please make sure to set the java.io.tmpdir of each agent to a unique path as described in the "How to configure temporary directory in Bamboo remote agent" page.
  • Check if the cache directories of each agent (when running multiple agents on single machine) are unique and not symlink-ed to a single location.
  • This issue persists even after clearing the repository cache on the server and agent sides.

Cause

Bamboo attempts to rebuild the cache every time it encounters an error while trying to update it – and in order to rebuild the cache Bamboo must first remove the existing one. Rebuilding the Git cache as many times as needed isn't necessarily an issue but it may become an issue if Bamboo has trouble clearing the cache folder. Bamboo will then enter a cycle it can't get out of where it is unable to update the cache but also unable to rebuild it. The Git cache will remain broken until someone intervenes.

Solution

Not every error causes the Git cache to be broken/ corrupted so it is possible to instruct Bamboo and agents to not clear the cache using the following system property.

Bamboo

  • Stop Bamboo.
  • Follow the steps inside the "Configuring your system properties" page to add the following Java property:

    -Dbamboo.native.git.folder.clearing.disabled=true
  • Start Bamboo.
  • The Source Code Checkout task should no longer fail with "fatal: not a git repository (or any of the parent directories): .git" messages.

Agents

You'll need to include the -Dbamboo.native.git.folder.clearing.disabled=true property as an additional Java argument in the <agent-home>/conf/wrapper.conf file:

  • Stop agent.
  • Navigate to <agent-home>/conf/wrapper.conf file and include the below line under the "# The Bamboo Agent home configuration file" section:
 # The Bamboo Agent home configuration file
 wrapper.java.additional.1=-Dbamboo.home=/Users/user1/Documents/Agents/bamboo-8.0.4
 wrapper.java.additional.2=-Dbamboo.agent.ignoreServerCertName=false
 wrapper.java.additional.3=-Dbamboo.allow.empty.artifacts=false
 wrapper.java.additional.4=-Dbamboo.native.git.folder.clearing.disabled=true
  • Start agent.
  • The Source Code Checkout task should no longer fail with "fatal: not a git repository (or any of the parent directories): .git" messages.
Last modified on Sep 6, 2022

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.