【问题标题】:How to use Git LFS with Azure Repos and Pipelines如何将 Git LFS 与 Azure Repos 和 Pipelines 结合使用
【发布时间】:2019-11-09 07:19:02
【问题描述】:

我有一个在 Azure Repos 中使用 Git LFS 的项目,其中使用 Git LFS 签入了几个二进制图像文件。当我的 Azure Pipelines 构建执行 git pull 时,图像文件不会从 Git LFS 中提取,我只剩下几个零字节图像文件。

我正在使用自定义的自托管 Azure Pipelines 构建服务器,该服务器上安装了最新版本的 Git LFS:

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

我尝试添加步骤来执行git lfs install,但这没有帮助。当我在登录到构建服务器后手动执行git lfs pull 时,文件已正确下载。当我在 Azure Pipeline 中运行 git lfs pull 作为构建步骤时,出现以下错误:

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'.

【问题讨论】:

    标签: git azure-pipelines git-lfs azure-repos


    【解决方案1】:

    您必须为 lfs 使用 https 才能与 Azure Devops 一起工作,并且在进行构建时您必须进行 LFS 签出:

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

    如果您使用的是 UI 向导,则会有一个复选框来检查 lfs

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

    【讨论】:

    • 这个结帐步骤对我有用,但 HTTPS 不是必需的。我正在使用 Azure DevOps 2019,其中服务器和构建代理位于同一个 Windows 域中。
    【解决方案2】:

    我认为这个错误很简单。 您尚未在管道中提供 git 凭据。

    更重要的是,我能问一下你为什么使用 git 来处理二进制文件吗? 你打算如何对 git 不理解的东西进行版本控制? 我的意思是,您打算如何在二进制文件上使用差异和合并等功能?

    【讨论】:

    • 我从未在其他存储库中明确调用 git lfs pull。我不明白为什么我必须在这里这样做,如果是的话,如何将凭据传递给它。这就是 Git LFS 的用途。许多存储库通常包含图像等二进制文件。
    • 使用 SSH 在你的 LFS 存储库上进行身份验证就可以了。 Github 上有一个很好的 Gist 解释了如何在 Git LFS github.com/git-lfs/git-lfs/blob/master/docs/api/…进行身份验证
    • 如果我们缺少一些关于如何执行此操作的 Azure Repos/Pipelines 特定信息,我会很感兴趣。
    猜你喜欢
    • 2019-03-26
    • 2020-03-17
    • 2021-10-06
    • 1970-01-01
    • 1970-01-01
    • 2021-05-27
    • 1970-01-01
    • 1970-01-01
    • 2022-06-14
    相关资源
    最近更新 更多