如何在AWS CodeBuild中使用Git LFS?

3

由于AWS CodeBuild似乎不支持git LFS(大文件系统),因此我尝试安装它:

version: 0.2

phases:
  install:
    commands:
      - apt-get install -y bash curl
      - curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | bash
      - apt-get install -y git-lfs
  pre_build:
    commands:
      - echo Downloading LFS files
      - git lfs pull
  build:
    commands:
      - echo Build started on `date`
  post_build:
    commands:
      - echo Build completed on `date`

针对上述代码,我得到了以下错误(已重命名仓库地址):
[Container] 2020/06/18 16:02:17 Running command git lfs pull
fatal: could not read Password for 'https://username@bitbucket.org': No such device or address
batch response: Git credentials for https://username@bitbucket.org/company/repo.git not found.
error: failed to fetch some objects from 'https://username@bitbucket.org/company/repo.git/info/lfs'

[Container] 2020/06/18 16:02:17 Command did not exit successfully git lfs pull exit status 2
[Container] 2020/06/18 16:02:17 Phase complete: PRE_BUILD State: FAILED
[Container] 2020/06/18 16:02:17 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error while executing command: git lfs pull. Reason: exit status 2

我还能做些什么来获取LFS文件吗?

3个回答

6

CodeBuild不支持Git LFS,但可以在运行时安装它,然后从源目录运行git lfs pull下载文件。操作如下:

env:
  git-credential-helper: yes

phases:
  install:
    commands:
      - cd /tmp/
      - curl -OJL https://github.com/git-lfs/git-lfs/releases/download/v2.13.2/git-lfs-linux-amd64-v2.13.2.tar.gz
      - tar xzf git-lfs-linux-amd64-v2.13.2.tar.gz
      - ./install.sh
      - cd $CODEBUILD_SRC_DIR

  pre_build:
    commands:
      - git lfs pull

<rest of your buildspec.yml file>

1
这对我没用。我收到了错误信息“不在一个git仓库中。” - undefined

2

CodeBuild 默认不支持 Git LFS。一种解决方法是手动安装,但仅在直接连接到 GitHub、BitBucket 或其他提供方(例如通过 SSH 密钥)时才有效。

如果您正在使用 CodePipeline 并且使用 存储库连接 (又名 "CodeStar Source Connections"),那么它将无法正常工作。当您以这种方式连接 BitBucket 或 GitHub 帐户时,它会创建某种不支持 git-lfs 资源的"代理":

batch response: Repository or object not found: https://codestar-connections.eu-central-1.amazonaws.com/git-http/[..].git/info/lfs/objects/batch

Check that it exists and that you have proper access to it

Failed to fetch some objects from 'https://codestar-connections.eu-central-1.amazonaws.com/git-http/[..].git/info/lfs'

然而,使用GitHub有一个解决方法:

GitHub CodeBuild git-lfs 解决方法

首先,您必须确保在流水线的源阶段中,源输出工件设置为{{link1:CODE_ZIP}},这等于控制台中的以下设置:

Output artifact format: CODE_ZIP

然后在GitHub中,进入存储库设置,确保git-lfs资源包含在源代码存档中:

GitHub include git lfs files in archive

这样就能正常工作了。现在由CodePipeline下载的源代码并经过CodeBuild传递,将包括git-lfs文件。


2

CodeBuild不支持原生的git LFS。解决方法是在buildspec.yml执行过程中设置Git LFS 1并克隆存储库2

在CodeBuild的buildspec中使用“git-credential-helper: yes”提供git命令的凭据3


我尝试过在buildspec.yml中添加'git-credential-helper: yes'来保持AWS CodeBuild上下文(即,不再克隆),但没有成功。你有任何想法为什么将git凭据添加到我的buildspec.yml失败了吗? - undefined
请检查此响应以获取建议:https://dev59.com/6VYM5IYBdhLWcg3wlQ3I - undefined

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接