Muhammad Rehan Saeed
Muhammad Rehan Saeed

Reputation: 38467

How to use Git LFS with Azure Repos and Pipelines

I have a project using Git LFS in Azure Repos with several binary image files being checked in using Git LFS. When my Azure Pipelines build performs a git pull, the image files are not pulled from Git LFS and I am left with several zero byte image files.

I'm using a custom self-hosted Azure Pipelines build server which has a recent version of Git LFS installed on it:

PS C:\rehan> git lfs --version                                                                                     git-lfs/2.7.2 (GitHub; windows amd64; go 1.12.2; git 08a08ae0)

I've tried adding steps to perform a git lfs install but that doesn't help. When I manually perform a git lfs pull after logging on to the build server, the files are downloaded correctly. When I run git lfs pull as a build step in my Azure Pipeline, I get the following error:

fatal: could not read Username for 'https://foo.visualstudio.com': terminal prompts disabled
batch response: Git credentials for https://foo.visualstudio.com/Bar/_git/Bar not found.
error: failed to fetch some objects from 'https://foo.visualstudio.com/Bar/_git/Bar.git/info/lfs'
Downloading LFS objects:   0% (0/1), 0 B | 0 B/s                                
##[error]PowerShell exited with code '1'.

Upvotes: 25

Views: 22068

Answers (4)

mvonballmo
mvonballmo

Reputation: 81

I'm going to add this answer promoting Naxin's comment from May 2023.

The solution that worked for me was the succinct,

You can also just delete the broken source that has been checked out (including the .git folder) and then re-run the pipeline (after adding lfs: true)

Upvotes: 3

htho
htho

Reputation: 1799

Unfortunately @4c74356b41's answer did not work for me. I have the same issue as @Haroon:

I configured the checkout step with lfs but the files stayed text files with hashes.

The solution was to manually run git lfs fetch and git lfs pull

  steps:
  - checkout: self
    lfs: true

  - script: |
     git lfs fetch
     git lfs pull
    displayName: git-lfs

Upvotes: 6

4c74356b41
4c74356b41

Reputation: 72171

You have to use https for lfs to work with Azure Devops and you have to do LFS checkout when doing the builds:

steps:
- checkout: self  # self represents the repo where the initial Pipelines YAML file was found
  lfs: true

if you are using a UI wizard there is a checkbox to checkout lfs

https://learn.microsoft.com/en-us/azure/devops/pipelines/yaml-schema?view=azure-devops&tabs=schema#checkout
https://learn.microsoft.com/en-us/azure/devops/pipelines/repos/pipeline-options-for-git?view=azure-devops#checkout-files-from-lfs

Upvotes: 62

Ryukote
Ryukote

Reputation: 794

I think that the error is pretty straight forward. You haven't provided git credentials in your pipepline.

And more important, can I ask why are you using git for binaries? How do you intend to have version control over something that git doesn't understand? By that I mean, how do you intend to use features like diff and merge on binary files?

Upvotes: -2

Related Questions