Xcode 服务器持续集成和 git lfs

标签 xcode git github git-lfs

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

我在集成之前添加了一个触发器来运行,我正在尝试执行“git lfs pull”,以便它将大文件 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
Could not checkout file 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 Could not checkout file

Could not write working directory file: Error opening media file. 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

最佳答案

以下是我如何让 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 b/c 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 

检查以确保 sudoers 是正确的:

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

关于Xcode 服务器持续集成和 git lfs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35068479/

相关文章:

ios - XCode 8.2.1 自动布局 : Issues with busy, 填充 UIViewControllers

git - Bitbucket 将功劳归功于错误的人

github - travis-ci安装程序发布--github-token

ios - 点击单元格时 Xcode UI 测试 XCTDaemonErrorDomain Code=13

objective-c - Objective-C 中是否可以创建一个具有两个父类(super class)的类?

git - * core.excludesfile 中的 war 导致 git add 忽略 *.p12 文件

git - 使用 gnu make 正确构建 git 子模块

macos - Git: 'rebase' 不是 git 命令。见 'git --help'

linux - 在 Debian 上使用 qtcreator 的 QSerialPort 问题

ios - 如何将 Facebook 的 Buck Build 安装到现有的 Xcode 项目中?