Facing a weird behaviour when we wanted to use git lfs to checkout a repository in a pipeline. When adding the step explicitly to the azure-pipeline.yml
- checkout: self
lfs: true
the pipeline fails with:
git: 'lfs' is not a git command. See 'git --help'.
##[error]Git-lfs installation failed with exit code: 1
Without the explicit checkout step we've seen that git-lfs
is actually pre-installed:
Syncing repository: repo-name (Git)
git version
git version 2.27.0
git lfs version
git-lfs/2.11.0 (GitHub; linux amd64; go 1.14.4)
however, it is not performing a git lfs checkout!
We've just figured out that this only happens when setting it additionally in the Edit Pipeline / Trigger > YAML Settings to LFS, refer to picture. This is not really clear for me why the lfs checkout fails when calling it explicitly as it's not installed, but otherwise it is indeed pre-installed, however, will only work if configured in the UI. Did I miss anything?
Summary:
If you're dealing with similar Git hook execution issues in Azure Pipelines, especially with container-based builds, ensure that Git and Git LFS are properly installed and accessible on the host machine where the checkout is taking place.
Details:
I think similar issue still may cause some difficulties. My initial suspicion was about how the hooks are executed by git
and I was not sure if the agent code provides environment variable for git. See the agent source: link
Information on git environment variables: link
Dokumentation of the checkout action: link
My initial attempt as a workaround I've provided environment setting using the env
parameter as follows:
- checkout: self
lfs: true
env:
GIT_EXEC_PATH: "/usr/lib/git-core:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
... which did not solve the issue for me. (Hmmm.)
After further investigation, I discovered that the root cause of my problem was related to the use of container-based builds. I had verified the installation of Git and Git LFS inside the container, but I overlooked the host. It turns out that the checkout process is executed on the host machine rather than within the container, as discussed in this GitHub issue. Notably, this detail is not clearly documented as of August 13, 2024.
Other potential error messages related to this topic:
git lfs install --local
git: 'lfs' is not a git command. See 'git --help'.
The most similar command is
log
##[error]Git-lfs installation failed with exit code: 1
OR
git checkout --progress --force 826e99df1ee98e47e82e0695246e447691678104
Previous HEAD position was 52f918d #fic conistent folder system
HEAD is now at 826e99d Update build-web-app.yaml for Azure Pipelines
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/post-checkout.
##[error]Git checkout failed with exit code: 1