Bamboo build fails with error "git: 'lfs' is not a git command"
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
Bamboo will try to build a build plan that requires git lfs, in a remote agent where git lfs is installed, and fails with the error "git: 'lfs' is not a git command".
Environment
Bamboo running with at least one remote agent.
Diagnosis
When the build is sent to the remote agent, the build will fail and in the server logs we will see:
com.atlassian.bamboo.repository.RepositoryException: : Cannot fetch branch 'feature/branch1' from 'ssh://git@gitserver:7999/project/repository.git' to source directory '/app/bamboo/bamboo-home/xml-data/build-dir/_git-repositories-cache/328a912ef82c8415aa64f494d23dbae966f741dc'. command [/app/bamboo/bamboo-home/git/bin/git lfs logs last] failed with code 1. Working directory was [/app/bamboo/bamboo-home/xml-data/build-dir/_git-repositories-cache/328a912ef82c8415aa64f494d23dbae966f741dc]., stderr:
git: 'lfs' is not a git command. See 'git --help'.
Cause
Even if the build is trying to be built in a remote agent, the problem relies on the server itself. The Bamboo server requires git lfs installed, even though there are no local agents configured. The reason for this is that Bamboo will perform a fetch before dispatching the build, and this is the actual operation that fails.
There can be cases where there is a plan that requires git lfs and still works fine, even though git lfs is not installed in the server. If you see this case, it is working because git lfs was not configured from the start, and Bamboo was able to create a local cache of the repository, making the fetch unnecessary.
Solution
Install git lfs in Bamboo server.
In case after installing git lfs on Bamboo server, the builds fail with the error "can’t execute git-lfs binary file", make sure to check if the newly installed git lfs executable is installed on the correct architecture, for example - if you try to run x86 executables on an ARM CPU, you can see this message. You can run the command "file git-lfs" to understand what sort of binary the file is.