Xcode服务器持续集成和Git LFS

4

我在Xcode中创建了一个机器人,用于我的项目的持续集成。

我添加了一个触发器,在集成之前运行,我试图做一个 "git lfs pull",以便将大文件拉入Xcode使用的临时目录来执行构建。

有什么方法可以让 "git lfs pull" 正常工作,以使集成成功?

当前我无法成功下载大文件。我的脚本如下:

#!/bin/bash

changeToRepo() {
    cd ${XCS_SOURCE_DIR}/My-Project-Name
}

changeToRepo
/usr/local/bin/git-lfs pull

然而,这些大文件并没有被下载下来,当我检查触发脚本的日志时,我看到了以下输出。

Git LFS: (0 of 1 files) 0 B / 139.13 MB

Git LFS: (0 of 1 files) 0 B / 139.13 MB
无法检出文件 git-lfs/1.1.0 (GitHub; darwin amd64; go 1.5.1; git 258acf1) git version 2.5.4 (Apple Git-61)

$ git-lfs pull 无法检出文件

无法写入工作目录文件:打开媒体文件时出错。 goroutine 66 [running]: github.com/github/git-lfs/lfs.Stack(0x0, 0x0, 0x0) /Users/rick/go/src/github.com/github/git-lfs/lfs/errors.go:557 +0x80 github.com/github/git-lfs/commands.logPanicToWriter(0x89a1e8, 0xc82002e018, 0x896028, 0xc82000e480) /Users/rick/go/src/github.com/github/git-lfs/commands/commands.go:184 +0xf7f github.com/github/git-lfs/commands.logPanic(0x896028, 0xc82000e480, 0x0, 0x0) /Users/rick/go/src/github.com/github/git-lfs/commands/commands.go:148 +0x421 github.com/github/git-lfs/commands.handlePanic(0x896028, 0xc82000e480, 0x0, 0x0) /Users/rick/go/src/github.com/github/git-lfs/commands/commands.go:123 +0x4e github.com/github/git-lfs/commands.LoggedError(0x896028, 0xc82000e480, 0x548060, 0x17, 0x0, 0x0, 0x0) /Users/rick/go/src/github.com/github/git-lfs/commands/commands.go:73 +0x82 github.com/github/git-lfs/commands.checkoutWithChan(0xc82012c4e0) /Users/rick/go/src/github.com/github/git-lfs/commands/command_checkout.go:202 +0x860 github.com/github/git-lfs/commands.checkoutFromFetchChan.func1(0xc82012c4e0, 0xc82018e040) /Users/rick/go/src/github.com/github/git-lfs/commands/command_checkout.go:78 +0x21 created by github.com/github/git-lfs/commands.checkoutFromFetchChan /Users/rick/go/src/github.com/github/git-lfs/commands/command_checkout.go:80 +0x439

2个回答

6
以下是我在机器人中使用git lfs的方法。首先,我编辑了我的机器人“集成前”触发器运行脚本,让它看起来像这样:

enter image description here

#!/bin/bash
export PATH="$PATH:/opt/local/bin:/opt/local/sbin:/usr/local/bin"
(cd ${XCS_SOURCE_DIR}/My-Project_Dir/My-Subfolder-Dir; sudo git lfs pull)

我们导出PATH是因为git lfs位于user/local/bin目录下(根据安装方式或服务器类型,可能适用其他位置)。否则,将找不到git lfs。
My-Project_Dir/My-Subfolder-Dir目录是项目的位置。Xcode服务器会将我的源代码下载到${XCS_SOURCE_DIR}这个临时文件夹,但是与我的大文件有关的.git文件位于My-Project_Dir/My-Subfolder-Dir中。
请注意,cd和git lfs命令位于括号内,这是因为cd命令生成了一个子进程。如果我们只有一行cd并在下一行使用git lfs,则目录不会保持更改,因为在子进程退出后,父进程仍处于初始目录中。除非我们在子进程中按顺序运行命令,否则git lfs命令将不会在新目录中发出。
另请注意,我需要在git lfs中使用sudo,否则git lfs就没有权限。该机器人正在以与我的服务器管理员空间不同的用户空间_xcsbuildd的用户名运行。
因此,请将_xcsbuildd用户添加到sudoers中。在终端中,使用以下命令:
$ sudo visudo

找到行“%admin ALL=(ALL) ALL”,按下“a”编辑文件,在其下方添加以下行:
_xcsbuildd ALL=(ALL) NOPASSWD: ALL

按 Esc 键,然后键入 :wq 即可保存并退出:

:wq 

请检查sudoers文件是否正确:

$ sudo cat /etc/sudoers | grep _xcsbuildd
_xcsbuildd ALL=(ALL) NOPASSWD: ALL 

1

大家好,我不确定原始解决方案是否有问题,但如果你遇到问题,可以尝试以下方法——在Xcode 9.2上通过Homebrew安装git-lfs,然后立即执行git lfs pull。这对我有效,并且不需要任何权限或sudo等操作。

#!/bin/sh -ex
pushd "${XCS_SOURCE_DIR:?}"

rm -rf homebrew
mkdir homebrew
curl -L "https://github.com/Homebrew/brew/tarball/master" | tar xz --strip 1 -C homebrew
export PATH="$PATH:$PWD/homebrew/bin"
brew install git-lfs

cd YourCheckedOutRepository
git lfs pull

popd

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