Command was canceled: command git failed with code -1
Problem
Whenever a build is triggered, the Source Code Checkout task fails and the following error is observed in the <BAMBOO_HOME>/logs/atlassian-bamboo.log file (or <BAMBOO_AGENT_HOME>/atlassian-bamboo-agent.log file if running on a remote agent):
[GitCommandProcessor] Command was canceled: command 'C:\Program Files (x86)\Git\cmd\git.exe' <insert-git-command-here> failed with code -1. Working directory was [\].
The problem may also occur at change detection time, before a build is even dispatched to the agent. This can cause the build to appeared as queued for lengthy period before eventually hitting the command timeout or fail instantly with the above error depending on the cause.
Diagnosis
Diagnostic Steps
- Does the failure happen quite quickly?
- Yes, the command fails almost instantly when performing
git version
. See Cause 1. - No, the command takes anywhere between a minute to hours before it eventually fails when performing
git fetch or git ls-remote
. See Cause 2.
- Yes, the command fails almost instantly when performing
Cause
- The Git capability path in Bamboo is incorrect or the user running the Bamboo or agent process doesn't have permissions to access the git installation path / executable.
- The configurable Command Timeout for the Repository under Advanced Options has been reached and the command has been aborted. The default for this setting is 180 minutes however this has been lower in previous versions of Bamboo.
Resolution
Cause 1: The Git capability path in Bamboo is incorrect or the user running the Bamboo or agent process doesn't have permissions to access the git installation path / executable
- Check where Git is actually installed on the machine where the build is running (local agents run on the same machine where Bamboo is running, remote agents usually run on separate machines).
- If the Git location was added to the system path, it's possible to run
"which git"
from the Terminal (Unix) or"where git"
from a Command Prompt (Windows) to check the path to the installation directory.
- If the Git location was added to the system path, it's possible to run
- Go to Bamboo and check the Git capability path as defined for the local Bamboo Server or agent machine. Check Viewing a capability page on how to locate this information.
- If there is mismatch between where Git is installed, compared to the capability path configured in Bamboo – update the capability in Bamboo to the correct path.
- Ensure that the user running the Bamboo or agent process has full access to the git executable at the installed path.
If Bamboo service or the remote agent is running on a Windows machine and you're using a Bamboo version below 6.10, it's possible that you are also being affected by the situation described at the Remote agent running as a Windows Service does not pick up the PATH variable correctly documentation.
Cause 2: The configurable Command Timeout for the Repository under Advanced Options has been reached and the command has been aborted.
- If you have a large repository that takes longer than the command timeout to perform the initial clone under normal circumstances, you may wish to increase the configured command timeout to allow Bamboo enough time to perform the fetch. This can be done at:
- Plan Configuration > Repositories > repository > Advanced Options > Command Timeout
- Investigate any network issues that may be causing the fetch from the repository to take longer than expected.
- Git Credential Manager for Windows under certain circumstances has been known to cause issues where the command hangs while waiting for user input / interaction (which cannot occur in an automated fashion) until the Command Timeout is eventually reached. This will typically affect the initial
git ls-remote
. See the below improvement request for workarounds:- BAM-18205 - Getting issue details... STATUS