我已经设置并构建了 Jenkins,由 git 提交等触发。示例日志如下所示:
00:00:00.016 Building in workspace D:\SomeWorkspace
00:00:00.016 > C:\Program Files (x86)\Git\bin\git.exe rev-parse --is-inside-work-tree # timeout=10
00:00:00.047 Fetching changes from the remote Git repository
00:00:00.047 > C:\Program Files (x86)\Git\bin\git.exe config remote.origin.url http://usr:pwd@gitRepoAddress.git/git/Repo.git # timeout=10
00:00:00.063 Fetching upstream changes from http://usr@gitRepoAddress.git/git/Repo.git
00:00:00.063 > C:\Program Files (x86)\Git\bin\git.exe --version # timeout=10
00:00:00.234 using .gitcredentials to set credentials
00:00:00.234 > C:\Program Files (x86)\Git\bin\git.exe config --local credential.helper store --file=\"C:\Path\To\Temp\git2724877017172338447.credentials\" # timeout=10
00:00:00.250 > C:\Program Files (x86)\Git\bin\git.exe fetch --tags --progress http://usr@gitRepoAddress.git/git/Repo.git +refs/heads/*:refs/remotes/origin/*
我想做的是查看这些 git 命令的输出,这样我就可以做一些事情,比如仔细检查它使用的是什么版本的 git,看看为什么 git fetch
很慢,等等。但是我不知道如何显示额外的输出。有任何想法吗?当我从安装在这个 Windows 机器上的 git-bash 运行这些命令时,git fetch
运行得更快,而且我不确定如何调试 Jenkins 中发生的事情。
最佳答案
Jenkins 中有两种可用的 git 实现,一种使用命令行“git.exe”工具,另一种使用 Java 实现,称为 JGit。根据您的示例输出,它使用前一个。
如果我们查看该实现,例如“fetch”命令,它似乎只是在成功时丢弃了输出。
fetch 命令的实现从这里开始(链接到回答时“master”的快照):
在 execute() 中向下一点,在第 313 行它调用 launchCommandWithCredentials(...);
返回命令的输出。然而,它没有存储在任何地方,因此被丢弃。
Tracking how the output is returned: The launchCommandWithCredentials method is implemented starting on line 1337. On line 1441 it calls
launchCommandIn(...);
which in turn is implemented starting on line 1672. On line 1689 it finally runs the actual command and on 1691 it collects the command output. If there return code is not 0, i.e. if there is some error, it throws an exception (also containing the command output) on line 1693, otherwise returns the command output. This is in turn returned by launchCommandWithCredentials 1441. Now we get back to line 313 where the return value is discarded.
查看 checkout 命令,似乎成功时输出也被丢弃。
所以看起来如果你真的需要你必须的输出
- 更改代码并运行修改后的版本,或者
- 在 https://github.com/jenkinsci/git-client-plugin 中打开一个问题并要求他们添加配置设置以启用输出的调试日志
关于git - 如何在我的 Jenkins 控制台日志中查看构建的 git 命令输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28070560/