My pipeline is failing with a Git LFS error

1 minute readKnowledge base

Issue

I have configured my pipeline job to use Git LFS pull after checkout but my pipeline still fails with the following error:

ERROR: Checkout failed
hudson.plugins.git.GitException: Command "git lfs pull origin" returned status code 1:
stdout:
stderr: git: 'lfs' is not a git command. See 'git --help'.

The most similar command is
	log

	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2671)
	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:2096)
	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$500(CliGitAPIImpl.java:84)
	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$9.execute(CliGitAPIImpl.java:3001)
Caused: hudson.plugins.git.GitException: Could not checkout
	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$9.execute(CliGitAPIImpl.java:3013)
	at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1344)
	at org.jenkinsci.plugins.workflow.steps.scm.SCMStep.checkout(SCMStep.java:129)
	at org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition.create(CpsScmFlowDefinition.java:159)
	at org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition.create(CpsScmFlowDefinition.java:70)
	at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:311)
	at hudson.model.ResourceController.execute(ResourceController.java:101)
	at hudson.model.Executor.run(Executor.java:442)
ERROR: Maximum checkout retry attempts reached, aborting
Finished: FAILURE

Resolution

As of the writing of this article, the cloudbees-core-mm image does not contain Git LFS.

Since version 2.249.2.3, cloudbees-core-agent does contain Git LFS :

docker run -it --rm cloudbees/cloudbees-core-agent:2.249.2.3 bash
[jenkins@30cfd142a94f ~]$ git lfs version
git-lfs/2.12.0 (GitHub; linux amd64; go 1.13.4; git dad7b9e6)

To resolve this error, the full SCM checkout must be done on the agent rather than the controller.

One way to achieve this is to ensure that lightweight checkout is enabled in your pipeline configuration. Lightweight checkouts ensure that only the Jenkinsfile is retrieved on the controller, rather than retrieving the full repository which in this case would require the use of git lfs.

After the Jenkinsfile is retrieved on the controller, the pipeline can then proceed to do a full checkout on the agent.