Git 使用 Jenkins 从共享文件夹上的存储库中拉取时挂起

Git hangs while pulling from repository on shared folder using Jenkins

我在我的工作中使用 Jenkins slave,slave 是 amazon spot 实例,所以我使用共享文件夹 (EFS) 来挂载 .m2/.npm 和工作区等共享文件夹。

当作业开始并尝试从远程 git 存储库中拉取时,构建在克隆时挂起。

当我不使用 efs 并在 spot 实例本身上克隆时,一切都按预期工作,手动或通过 Jenkins 在 efs 上创建其他文件也可以正常工作。 共享文件夹的权限与 Jenkins 使用的用户相同。

任何可能导致此行为的建议?

这是构建日志:

11:41:20 Fetching upstream changes from git@git.assembla.com:alpha.saas.git
11:41:20  > git --version # timeout=10
11:41:20 using GIT_SSH to set credentials jenkins@Dev_Builder(ssh)
11:41:20  > git fetch --no-tags --progress git@git.assembla.com:alpha.saas.git +refs/heads/*:refs/remotes/origin/* # timeout=5
11:41:29  > git rev-parse refs/remotes/origin/master^{commit} # timeout=10
11:41:29  > git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
11:41:29 Checking out Revision e0dd60499d693a40fa0d3669201437b49cc2b0c4 (refs/remotes/origin/master)
11:41:29  > git config core.sparsecheckout # timeout=10
11:41:29  > git checkout -f e0dd60499d693a40fa0d3669201437b49cc2b0c4
11:48:59 Build was aborted

看来问题出在 git 中的 Packfile 过大, 看起来 EFS 处理如此大的文件非常慢,这导致它挂了这么久。 我通过使用 lsof 命令注意到了它:

lsof +D ./

指出索引文件和打包文件打开时间很长,而且它们都是大文件:

./.git/objects/pack/pack-601f9b58380bc69d49bcc429d046c8940c5ed9d2.idx

./.git/objects/pack/pack-601f9b58380bc69d49bcc429d046c8940c5ed9d2.pack

为了解决这个问题,我在 Jenkins 中使用了浅层克隆:

checkout([
        $class: 'GitSCM',
        branches: [[name: "$git_branch" ]],
        doGenerateSubmoduleConfigurations: false,
        extensions: [[$class: 'CloneOption', depth: 0, noTags: true, reference: '', shallow: true]],
        submoduleCfg: [],
        userRemoteConfigs: [[url: "$git_repo" , credentialsId: env.gitCredentialsJenkins]]])

虽然克隆 1.8GB 存储库仍然需要很长时间,但问题已解决。