git - 如何解析 stderr : fatal: Not a valid object name HEAD in jenkins?

标签 git jenkins

我正在尝试通过 Jenkins 从 git 获取最新代码。每次我这样做时,我都会收到以下错误。我已经通过几个关于 stackoverflow 的链接关注了这个,但它们似乎都没有解决这个问题。

  1. 尝试删除整个工作区,然后再次运行。它会抛出同样的错误。
  2. 在执行 shell 构建选项中包含 git reset --hard

这里是错误。

Checking out Revision bc304892eadfaaf7338fa6e5f370137555d7cfd9 (refs/remotes/origin/master)
 > C:\Program Files\Git\bin\git.exe config core.sparsecheckout # timeout=10
 > C:\Program Files\Git\bin\git.exe config core.sparsecheckout true # timeout=10
 > C:\Program Files\Git\bin\git.exe read-tree -mu HEAD # timeout=10
Command "C:\Program Files\Git\bin\git.exe read-tree -mu HEAD" returned status code 128:
stdout: 
stderr: fatal: Not a valid object name HEAD

 > C:\Program Files\Git\bin\git.exe checkout -f bc304892eadfaaf7338fa6e5f370137555d7cfd9
FATAL: Could not checkout bc304892eadfaaf7338fa6e5f370137555d7cfd9
hudson.plugins.git.GitException: Could not checkout bc304892eadfaaf7338fa6e5f370137555d7cfd9
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$8.execute(CliGitAPIImpl.java:1907)
    at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler$1.call(RemoteGitImpl.java:152)
    at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler$1.call(RemoteGitImpl.java:145)
    at hudson.remoting.UserRequest.perform(UserRequest.java:120)
    at hudson.remoting.UserRequest.perform(UserRequest.java:48)
    at hudson.remoting.Request$2.run(Request.java:326)
    at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:68)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at hudson.remoting.Engine$1$1.run(Engine.java:62)
    at java.lang.Thread.run(Unknown Source)
    at ......remote call to odesk.delta.04(Native Method)
    at hudson.remoting.Channel.attachCallSiteStackTrace(Channel.java:1416)
    at hudson.remoting.UserResponse.retrieve(UserRequest.java:220)
    at hudson.remoting.Channel.call(Channel.java:781)
    at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler.execute(RemoteGitImpl.java:145)
    at sun.reflect.GeneratedMethodAccessor434.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler.invoke(RemoteGitImpl.java:131)
    at com.sun.proxy.$Proxy51.execute(Unknown Source)
    at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1060)
    at hudson.scm.SCM.checkout(SCM.java:485)
    at hudson.model.AbstractProject.checkout(AbstractProject.java:1276)
    at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:607)
    at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:86)
    at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:529)
    at hudson.model.Run.execute(Run.java:1738)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
    at hudson.model.ResourceController.execute(ResourceController.java:98)
    at hudson.model.Executor.run(Executor.java:410)
Caused by: hudson.plugins.git.GitException: Command "C:\Program Files\Git\bin\git.exe checkout -f bc304892eadfaaf7338fa6e5f370137555d7cfd9" returned status code 128:
stdout: 
stderr: error: Sparse checkout leaves no entry on working directory

    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1640)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$500(CliGitAPIImpl.java:62)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$8.execute(CliGitAPIImpl.java:1899)
    at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler$1.call(RemoteGitImpl.java:152)
    at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler$1.call(RemoteGitImpl.java:145)
    at hudson.remoting.UserRequest.perform(UserRequest.java:120)
    at hudson.remoting.UserRequest.perform(UserRequest.java:48)
    at hudson.remoting.Request$2.run(Request.java:326)
    at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:68)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at hudson.remoting.Engine$1$1.run(Engine.java:62)
    at java.lang.Thread.run(Unknown Source)
Finished: FAILURE

最佳答案

我相信你有两个问题。

第一个:

Command "C:\Program Files\Git\bin\git.exe read-tree -mu HEAD" returned 
status code 128:
stdout: 
stderr: fatal: Not a valid object name HEAD

实际上是相对无害的。我们遇到了同一个人。这是由于读取树调用是在 checkout 之前完成的。 ref HEAD 在 checkout 后设置。在我们的例子中,这个错误没有造成任何进一步的问题。我们设法通过在 checkout 前不进行全面删除而只进行清洁来摆脱这一问题。

真正的问题是第二个错误:

Caused by: hudson.plugins.git.GitException: Command "C:\Program Files\Git\bin\git.exe checkout -f bc304892eadfaaf7338fa6e5f370137555d7cfd9"     returned status code 128:
stdout: 
stderr: error: Sparse checkout leaves no entry on working directory

我们也遇到了这个问题。在我们的例子中,这是由稀疏 checkout 中的错误路径引起的。仔细检查您输入的路径是否正确。

关于git - 如何解析 stderr : fatal: Not a valid object name HEAD in jenkins?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41582949/

相关文章:

git - 如何使用 Git 管理我的 greasemonkey 用户脚本(以便将它们托管在 GitHub 中)

git - 从服务器 pull 时如何 merge 和消除git中的冲突

git - 防止从分支推送到特定的远程

jenkins - 如何获取触发 Jenkins 构建的 "changes"(提交消息)?

Jenkins-pipeline 从 groovy 中的属性文件中提取并设置变量

docker - Docker-套接字文件的卷映射是否是覆盖行为?

git - 使用 CopSSH 在 Windows 上设置 Git 服务器,但出现此错误 : does not appear to be a git repository

git - 如何将 Hudson 构建指向我的本地 git 存储库?

jenkins - 使用动态项目名称替代项复制工件构建步骤

Jenkins 管道实用程序步骤 - zip zipFile