Pipelines failing with 'This repository is configured for Git LFS but 'git-lfs' was not found on your path'
Platform Notice: Cloud - This article applies to Atlassian products on the cloud platform.
Summary
When pushing back to a repository within a Bitbucket Pipelines build, a user might come across the error message 'This repository is configured for Git LFS but 'git-lfs' was not found on your path' if the docker image does not have git-lfs installed and the pipeline was configured to clone LFS files.
Cause
By default, in Bitbucket Pipelines the LFS files of the repository are not cloned into the build container during the build setup phase. However, it's possible to instruct pipelines to include the LFS files in the clone by using the following attribute in the step:
pipelines:
default:
- step:
name: Clone with lfs on
clone:
lfs: true
script:
- ls -lh large-file.zip # 26M large-file.zip
- touch "FileA.txt"
- git add FileA.txt
- git commit -m "[skip ci] My commit from pipelines"
- git push
or at the global level, which would apply to all steps :
clone:
lfs: true
pipelines:
default:
- step:
name: Clone and download
script:
- echo "Clone and download my LFS files!"
- touch "FileA.txt"
- git add FileA.txt
- git commit -m "[skip ci] My commit from pipelines"
- git push
This will make all the LFS files in your repository to be downloaded into the build container during the build setup phase. However, when pushing back to your repository from the pipeline, git will also check if there was any change in the cloned LFS file, and to perform this git-lfs operation, the 'git-lfs' package needs to be installed in the docker image being used in the step.
If the 'git-lfs' package is not installed in the image, the git push command will fail with the error message
This repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting '.git/hooks/pre-push'.
error: failed to push some refs to 'bitbucket.org:<workspace>/<repository>.git'
Solution
The git-lfs package can be installed during build time by including the following command into the step's script :
- step:
name: Clone with lfs on
clone:
lfs: true
script:
- curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | bash
- apt-get install -y git-lfs
- [... rest of your script ...]
This will download and install git-lfs plugin into the build container, and after it's installed, the next commands in your script will be able to use git-lfs as usual, including git push.
Alternatively, if you are using your own custom docker image in the pipeline step, you can include the git-lfs installation commands directly in your Dockerfile, so the git-lfs becomes part of the image. This would prevent having to install git-lfs on the bitbucket-pipelines.yml script every time the build is executed.