Xcode服务器持续集成和git lfs
我在Xcode中创建了一个bot,用于持续集成我的项目。Xcode服务器持续集成和git lfs
我添加了一个触发器,在集成之前运行,我试图做一个“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 1文件)0 B/139.13 MB
GIT中LFS:(0 1文件)0 B/139.13 MB
未能进行结帐文件GIT-LFS/1.1。 0(GitHub的;达尔文AMD64;去1.5.1; 混帐258acf1)Git版本2.5.4(苹果的Git-61)$ GIT-LFS拉莫非不结账文件
无法写入工作目录下的文件:打开媒体文件时出错。 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,0x548 060,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由github.com/github/git-lfs/commands创建.checkoutFromFetchChan /Users/rick/go/src/github.com/github/git-lfs/commands/command_checkout.go:80 + 0x439
下面是我如何让git lfs在bot中工作。首先,我编辑我的机器人触发运行脚本“集成之前,”看起来像这样:
#!/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)
我们出口的路径B/C的git LFS住用户/ 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命令不会在子进程中的新目录中发布,除非我们在该子进程内按顺序运行命令。
另请注意,我需要使用sudo与git lfs,否则git lfs没有权限。机器人运行在与我的服务器管理空间不同的用户空间中,用户名为_xcsbuildd。
因此,将_xcsbuildd用户添加到sudoers。在终端,使用以下命令:
$ sudo visudo
找到行“%联系ALL =(ALL)”,按“一”编辑文件,并在其下方添加以下行:
_xcsbuildd ALL=(ALL) NOPASSWD: ALL
按Esc键,然后编写和输入quit:
:wq
检查以确保在sudoers是正确的:
$ sudo cat /etc/sudoers | grep _xcsbuildd
_xcsbuildd ALL=(ALL) NOPASSWD: ALL
我不确定原始解决方案是否存在问题,但是如果您遇到问题,请尝试下面的内容 - 它适用于Xcode 9.2的Xcode Build Server /不需要任何权限/ sudoing等。基本上它是关于通过自制软件安装git-lfs并在此之后执行git lfs pull
。
#!/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