Git 强制推送后,Xcode 持续集成机器人失败

4
我们设置了一个Xcode CI机器人来轮询我们的git仓库,以便根据新提交构建。通常情况下,它运行得很好。然而,在强制推送后(我知道),机器人将失败,并且再也无法正确构建。解决方案是删除机器人并重新开始(并谴责自己强制推送)。
在Xcode构建日志中没有错误,在控制台上只能确认问题是什么(请参见最后一条日志)。
Jan 28 08:15:51 macmini.local xcsbuildd[80853]: [CSBotSCMAction gitCloneRepositoryAtURL:branch:destinationPath:createDirectoryNamed:completionBlock:] : https://github.com/XXXXXXXX/iOS.git
Jan 28 08:15:51 macmini.local xcsbuildd[80853]: newRepoURL: https://github.com/XXXXXXXX/iOS.git
    "https:\/\/githubuserformacmini@github.com\/XXXXXXXX\/iOS.git",
    "https_github_com_XXXXXXXX_iOS_git"
  "launchCommand" : "\/Applications\/Xcode.app\/Contents\/Developer\/usr\/bin\/git clone https:\/\/githubuserformacmini@github.com\/XXXXXXXX\/iOS.git --recursive --verbose --progress https_github_com_XXXXXXXX_iOS_git",
  "launchPath" : "\/Applications\/Xcode.app\/Contents\/Developer\/usr\/bin\/git",
    "GIT_ASKPASS" : "\/Applications\/Server.app\/Contents\/ServerRoot\/usr\/libexec\/xcs_ssh_auth_agent",
Jan 28 08:18:29 macmini.local xcsbuildd[80853]: Obtaining the HEAD hash at: /Library/Server/Xcode/Data/BotRuns/BotRun-187dbc1a-dae2-4ddc-a75b-75831de7ff09.bundle/tmp/https_github_com_XXXXXXXX_iOS_git
Jan 28 08:18:29 macmini.local xcsbuildd[80853]: [CSBotSCMAction gitHeadHashesRepositoryAtPath:branch:completionBlock:] : /Library/Server/Xcode/Data/BotRuns/BotRun-187dbc1a-dae2-4ddc-a75b-75831de7ff09.bundle/tmp/https_github_com_XXXXXXXX_iOS_git
Jan 28 08:18:29 macmini.local xcsbuildd[80853]: newRepoURL: file:///Library/Server/Xcode/Data/BotRuns/BotRun-187dbc1a-dae2-4ddc-a75b-75831de7ff09.bundle/tmp/https_github_com_XXXXXXXX_iOS_git/
  "launchCommand" : "\/Applications\/Xcode.app\/Contents\/Developer\/usr\/bin\/git show-ref --heads",
  "launchPath" : "\/Applications\/Xcode.app\/Contents\/Developer\/usr\/bin\/git",
  "currentDirectoryPath" : "\/Library\/Server\/Xcode\/Data\/BotRuns\/BotRun-187dbc1a-dae2-4ddc-a75b-75831de7ff09.bundle\/tmp\/https_github_com_XXXXXXXX_iOS_git",
  "launchCommand" : "\/Applications\/Xcode.app\/Contents\/Developer\/usr\/bin\/git checkout release",
  "launchPath" : "\/Applications\/Xcode.app\/Contents\/Developer\/usr\/bin\/git",
    "GIT_ASKPASS" : "\/Applications\/Server.app\/Contents\/ServerRoot\/usr\/libexec\/xcs_ssh_auth_agent",
  "currentDirectoryPath" : "\/Library\/Server\/Xcode\/Data\/BotRuns\/BotRun-187dbc1a-dae2-4ddc-a75b-75831de7ff09.bundle\/tmp\/https_github_com_XXXXXXXX_iOS_git",
Jan 28 08:18:29 macmini.local xcsbuildd[80853]: [CSBotSCMAction gitHeadHashesRepositoryAtPath:branch:completionBlock:] : https://github.com/XXXXXXXX/iOS.git
Jan 28 08:18:29 macmini.local xcsbuildd[80853]: newRepoURL: https://github.com/XXXXXXXX/iOS.git
    "https:\/\/githubuserformacmini@github.com\/XXXXXXXX\/iOS.git"
  "launchCommand" : "\/Applications\/Xcode.app\/Contents\/Developer\/usr\/bin\/git ls-remote --heads https:\/\/githubuserformacmini@github.com\/XXXXXXXX\/iOS.git",
  "launchPath" : "\/Applications\/Xcode.app\/Contents\/Developer\/usr\/bin\/git",
    "GIT_ASKPASS" : "\/Applications\/Server.app\/Contents\/ServerRoot\/usr\/libexec\/xcs_ssh_auth_agent",
Jan 28 08:18:30 macmini.local xcsbuildd[80853]: [CSBotSCMAction gitCommitSummaryForRepositoryURL:betweenHashIdentifier:andHashIdentifier:completionBlock:] : /Library/Server/Xcode/Data/BotRuns/BotRun-187dbc1a-dae2-4ddc-a75b-75831de7ff09.bundle/tmp/https_github_com_XXXXXXXX_iOS_git
  "launchCommand" : "\/Applications\/Xcode.app\/Contents\/Developer\/usr\/bin\/git log --no-color --name-status --format=fuller --date=iso e478616e4b3915846f7938fec24e8dc12cdae52a..f2c1b24a6b801ed9f7e60dce60add1851618da64",
  "launchPath" : "\/Applications\/Xcode.app\/Contents\/Developer\/usr\/bin\/git",
    "GIT_ASKPASS" : "\/Applications\/Server.app\/Contents\/ServerRoot\/usr\/libexec\/xcs_ssh_auth_agent",
  "currentDirectoryPath" : "\/Library\/Server\/Xcode\/Data\/BotRuns\/BotRun-187dbc1a-dae2-4ddc-a75b-75831de7ff09.bundle\/tmp\/https_github_com_XXXXXXXX_iOS_git",
Jan 28 08:18:30 macmini.local xcsbuildd[80853]: [XCSCheckoutOperation.m:1033 7d02a310 +168ms] Error getting Git commit log in range e478616e4b3915846f7938fec24e8dc12cdae52a:f2c1b24a6b801ed9f7e60dce60add1851618da64 <stderr>= fatal: Invalid revision range e478616e4b3915846f7938fec24e8dc12cdae52a..f2c1b24a6b801ed9f7e60dce60add1851618da64
Jan 28 08:18:30 macmini.local xcsbuildd[80853]: [XCSCheckoutOperation.m:610 7d02a310 +0ms] Failed to get Git commit history for repo with error Error Domain=CSBotSCMAction Code=-1000 "fatal: Invalid revision range e478616e4b3915846f7938fec24e8dc12cdae52a..f2c1b24a6b801ed9f7e60dce60add1851618da64

我可以看到...
git log --no-color --name-status --format=fuller --date=iso e478616e4b3915846f7938fec24e8dc12cdae52a..f2c1b24a6b801ed9f7e60dce60add1851618da64

...来自集成的内容。 e478616e4b3915846f7938fec24e8dc12cdae52a 是在我强制使用 f2c1b24a6b801ed9f7e60dce60add1851618da64 时被删除的提交(我猜测)。我不知道机器人在哪里保留这些信息。我尝试从 /Library/Server/Xcode/Data/BotRuns 中删除所有内容,但没有起作用。我想也许它是从 /Library/Server/Xcode/Data/BotRuns/Latest 中获取最后一个哈希值,但是并不是这样。我还在 /Library/Server/Xcode 的许多其他目录中进行了挖掘,但没有看到任何东西。

如果 Xcode 的 CI 方法能够给我们对 git 工作流程的任何控制就好了。配置选项非常少。也许删除是唯一的方法。


“Git”通过运行“post-receive”钩子获取此信息。如果您可以发布“post-receive”钩子代码,那么也许有人可以提供帮助。 - First Zero
很不幸,所有在post-receive hook中发生的事情都被编译并锁定在某个应用程序的CSBotSCMAction类下(至少从日志中我能够得出这个结论)。谢谢。 - rob5408
1个回答

1
似乎有人删除了已经推送到远程的提交。大多数CI服务器使用以下基本工作流程检测存储库中的更改:
  1. 从远程获取
  2. 执行git log或diff,其中起始提交是克隆存储库的当前HEAD,而结束提交是克隆存储库正在跟踪的远程分支的当前HEAD

如果当前签出分支的HEAD在远程存储库中被删除,则Git可能会失败。

您可以尝试进入CI构建具有Git存储库签出的目录,并执行以下操作:

git reset --hard origin/branch_name

这将使您的本地和远程分支保持一致。然后,您可能需要启动手动构建。
真正的答案是不要在已经推送到远程的提交中更改Git的提交历史记录。

嗨,Greg,那绝对是这样的。而且,“大多数CI服务器”需要记住它是苹果公司,他们可能有自己更好或更糟糕的方法。存储库的位置也被隐藏在几个锁定的目录后面。有足够的警告标志告诉我我可能不应该进去。 - rob5408
我明白了。好的 :) - Greg Burghardt
@rob5408,公平地说,有权限确保您不会随意进入那里。这并不意味着您不应该至少访问它们。进入这些目录可能会让您了解此问题和其他问题的内部情况。 - Chris

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