Failed build with 'git fetch' command failed
Recently I have had this following issue when I create a new project in TeamCity:
Failed to build patch for build #1 {build id=3614, buildTypeId=BlogApi_Build}, VCS root: "https://gitlab.com/my-repo/my-repo.git#refs/heads/main" {instance id=35, parent internal id=145, parent id=BlogApi_HttpsGitlabComBlog125apisBlogApiGitRefsHeadsMain, description: "https://gitlab.com/my-repo/my-repo.git#refs/heads/main"}, due to error: 'git fetch' command failed (repository dir: <TeamCity data dir>/system/caches/git/git-6C486741.git).
exception: com.intellij.execution.process.ProcessNotCreatedException: Cannot run program "/usr/lib/jvm/java-21-openjdk-amd64/bin/java" (in directory "/root/.BuildServer/system/caches/git/git-6C486741.git"): error=0, Failed to exec spawn helper: pid: 895419, exit value: 1
exit code: -1
Repository sources transferred (748 B)
Will repeat attempt when server will be available, number of attempts left: 1
Updating sources: auto checkout (on server)
Will use server side checkout: No supported VCS client found on the agent for vcs root 'https://gitlab.com/my-repo/my-repo.git#refs/heads/main'. Details: Unable to run Git at path /usr/bin/git: /usr/bin/git version command failed.
exit code: -1
exception: com.intellij.execution.process.ProcessNotCreatedException: Cannot run program "/usr/bin/git" (in directory "."): error=0, Failed to exec spawn helper: pid: 895394, exit value: 1
Building and caching clean patch for VCS root: https://gitlab.com/my-repo/my-repo.git#refs/heads/main
Failed to build patch for build #1 {build id=3614, buildTypeId=BlogApi_Build}, VCS root: "https://gitlab.com/my-repo/my-repo.git#refs/heads/main" {instance id=35, parent internal id=145, parent id=BlogApi_HttpsGitlabComBlog125apisBlogApiGitRefsHeadsMain, description: "https://gitlab.com/my-repo/my-repo.git#refs/heads/main"}, due to error: 'git fetch' command failed (repository dir: <TeamCity data dir>/system/caches/git/git-6C486741.git).
exception: com.intellij.execution.process.ProcessNotCreatedException: Cannot run program "/usr/lib/jvm/java-21-openjdk-amd64/bin/java" (in directory "/root/.BuildServer/system/caches/git/git-6C486741.git"): error=0, Failed to exec spawn helper: pid: 895428, exit value: 1
exit code: -1
Repository sources transferred (748 B)
Patch is broken, can be found in file: /home/my-pc/Desktop/DevOps/TeamCity/buildAgent/temp/buildTmp/temp9967238314985330842patch_3614
jetbrains.buildServer.agent.impl.patch.PatchDownloaderImpl$1: Server was not able to build correct patch, most likely due to VCS errors
at jetbrains.buildServer.agent.impl.patch.PatchDownloaderImpl.throwError(PatchDownloaderImpl.java:156)
at jetbrains.buildServer.agent.impl.patch.PatchDownloaderImpl.checkPatch(PatchDownloaderImpl.java:146)
at jetbrains.buildServer.agent.impl.patch.PatchDownloaderImpl.copyPatchAndCheckFile(PatchDownloaderImpl.java:78)
at jetbrains.buildServer.agent.impl.patch.PatchDownloaderImpl.copyPatchAndCheck(PatchDownloaderImpl.java:98)
at jetbrains.buildServer.agent.impl.patch.UpdateSourcesPatcherBase.copyPatchToTempFile(UpdateSourcesPatcherBase.java:65)
at jetbrains.buildServer.agent.impl.patch.UpdateSourcesFromServer.updateSources(UpdateSourcesFromServer.java:45)
at jetbrains.buildServer.agent.impl.patch.AbstractSourcesUpdater.doSourceUpdate(AbstractSourcesUpdater.java:52)
at jetbrains.buildServer.agent.impl.patch.CheckoutSourcesBuildStage$CheckoutAction.checkout(CheckoutSourcesBuildStage.java:116)
at jetbrains.buildServer.agent.impl.patch.CheckoutSourcesBuildStage$1.checkout(CheckoutSourcesBuildStage.java:65)
at jetbrains.buildServer.agent.impl.patch.CheckoutSourcesBuildStage.doCheckout(CheckoutSourcesBuildStage.java:81)
at jetbrains.buildServer.agent.impl.patch.CheckoutSourcesBuildStage.doRecoverableStage(CheckoutSourcesBuildStage.java:61)
at jetbrains.buildServer.agent.impl.buildStages.startStages.RecoverableBuildStage.doLastAttempt(RecoverableBuildStage.java:114)
at jetbrains.buildServer.agent.impl.buildStages.startStages.RecoverableBuildStage.doBuildStage(RecoverableBuildStage.java:72)
at jetbrains.buildServer.agent.impl.buildStages.BuildStagesExecutor$1.callStage(BuildStagesExecutor.java:33)
at jetbrains.buildServer.agent.impl.buildStages.BuildStagesExecutor$1.callStage(BuildStagesExecutor.java:24)
at jetbrains.buildServer.agent.impl.buildStages.StagesExecutor.callRunStage(StagesExecutor.java:76)
at jetbrains.buildServer.agent.impl.buildStages.StagesExecutor.doStages(StagesExecutor.java:35)
at jetbrains.buildServer.agent.impl.buildStages.BuildStagesExecutor.doStages(BuildStagesExecutor.java:24)
at jetbrains.buildServer.agent.impl.BuildRunActionImpl.doStages(BuildRunActionImpl.java:97)
at jetbrains.buildServer.agent.AgentOperationModeEx.executeRunnerStages(AgentOperationModeEx.java:47)
at jetbrains.buildServer.agent.impl.BuildRunActionImpl.runBuild(BuildRunActionImpl.java:68)
at jetbrains.buildServer.agent.impl.BuildAgentImpl.doActualBuild(BuildAgentImpl.java:350)
at jetbrains.buildServer.agent.impl.BuildAgentImpl.access$100(BuildAgentImpl.java:62)
at jetbrains.buildServer.agent.impl.BuildAgentImpl$1.run(BuildAgentImpl.java:299)
at java.base/java.lang.Thread.run(Thread.java:1583)
Caused by: jetbrains.buildServer.vcs.patches.UnsuccessfulPatchException: Failed to build patch for build #1 {build id=3614, buildTypeId=BlogApi_Build}, VCS root: "https://gitlab.com/my-repo/my-repo.git#refs/heads/main" {instance id=35, parent internal id=145, parent id=BlogApi_HttpsGitlabComBlog125apisBlogApiGitRefsHeadsMain, description: "https://gitlab.com/my-repo/my-repo.git#refs/heads/main"}, due to error: 'git fetch' command failed (repository dir: <TeamCity data dir>/system/caches/git/git-6C486741.git).
exception: com.intellij.execution.process.ProcessNotCreatedException: Cannot run program "/usr/lib/jvm/java-21-openjdk-amd64/bin/java" (in directory "/root/.BuildServer/system/caches/git/git-6C486741.git"): error=0, Failed to exec spawn helper: pid: 895428, exit value: 1
exit code: -1
at jetbrains.buildServer.vcs.patches.AbstractPatcher$1.fail(AbstractPatcher.java:103)
at jetbrains.buildServer.vcs.patches.LowLevelPatcher.readPatchStream(LowLevelPatcher.java:186)
at jetbrains.buildServer.vcs.patches.LowLevelPatcher.applyPatch(LowLevelPatcher.java:105)
at jetbrains.buildServer.vcs.patches.AbstractPatcher.applyPatch(AbstractPatcher.java:43)
at jetbrains.buildServer.agent.impl.patch.PatchApplierImpl.applyPatch(PatchApplierImpl.java:19)
at jetbrains.buildServer.agent.impl.patch.PatchDownloaderImpl.checkPatchInFileIsCompleted(PatchDownloaderImpl.java:108)
at jetbrains.buildServer.agent.impl.patch.PatchDownloaderImpl.checkPatch(PatchDownloaderImpl.java:136)
... 23 more
Failed to build patch for build #1 {build id=3614, buildTypeId=BlogApi_Build}, VCS root: "https://gitlab.com/my-repo/my-repo.git#refs/heads/main" {instance id=35, parent internal id=145, parent id=BlogApi_HttpsGitlabComBlog125apisBlogApiGitRefsHeadsMain, description: "https://gitlab.com/my-repo/my-repo.git#refs/heads/main"}, due to error: 'git fetch' command failed (repository dir: <TeamCity data dir>/system/caches/git/git-6C486741.git).
exception: com.intellij.execution.process.ProcessNotCreatedException: Cannot run program "/usr/lib/jvm/java-21-openjdk-amd64/bin/java" (in directory "/root/.BuildServer/system/caches/git/git-6C486741.git"): error=0, Failed to exec spawn helper: pid: 895428, exit value: 1
exit code: -1
Publishing artifacts
Collecting files to publish: [/home/my-pc/Desktop/DevOps/TeamCity/buildAgent/temp/agentTmp/build_stages.txt=>.teamcity/perfmon/]
Publishing 1 file using [WebPublisher]: /home/my-pc/Desktop/DevOps/TeamCity/buildAgent/temp/agentTmp/build_stages.txt => .teamcity/perfmon
Publishing 1 file using [ArtifactsCachePublisherImpl]: /home/my-pc/Desktop/DevOps/TeamCity/buildAgent/temp/agentTmp/build_stages.txt => .teamcity/perfmon
Publishing artifacts
Collecting files to publish: [/home/my-pc/Desktop/DevOps/TeamCity/buildAgent/temp/buildTmp/.teamcity/docker/build_1/events.json => .teamcity/docker/]
Publishing internal artifacts
Publishing 1 file using [WebPublisher]
Publishing 1 file using [WebPublisher]: /home/my-pc/Desktop/DevOps/TeamCity/buildAgent/temp/buildTmp/.teamcity/docker/build_1/events.json => .teamcity/docker
I have tried removing /root/.BuildServer/system/caches, but it does not work.
I suspect the agent does not have permission to run git fetch in the teamcity data.
My TeamCity info:
- Version: 2024.12.2 (build 174504)
- OS: 24.04
Any solutions please ?
Thanks,
Please sign in to leave a comment.
Hi,
The error you're encountering seems to stem from the inability of the TeamCity agent to run certain commands (git fetch) due to permission issues or missing executables.
1. Check Permissions for /root/.BuildServer/system/caches and Git Directories
- Ensure that the TeamCity agent has proper read/write access to the directories mentioned in the logs (especially the cache and Git directories). The agent might be running as a non-root user, but the cache directories are owned by root, causing permission issues.
- You can change the ownership of these directories by running:
- Ensure the agent user has access to the .BuildServer directory as well.
2. Verify Git Installation and Path
The logs show an issue with the command git fetch. It's important to verify that the git command is properly installed and accessible by the TeamCity agent.
Run the following commands to confirm that Git is installed and available in the system path:
Make sure the TeamCity agent has access to Git (/usr/bin/git as indicated in your logs). If it's missing, install Git using:
Check the detailed logs of the TeamCity agent (teamcity-agent.log)to see if there are any additional errors or configuration issues related to permissions.
Best Regards,
Tom