git - 如何在我的 Jenkins 控制台日志中查看构建的 git 命令输出?

标签 git jenkins jenkins-plugins

我已经设置并构建了 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”的快照):

https://github.com/jenkinsci/git-client-plugin/blob/1a450a5ee993209cc9f27f2a4bfb31bc08a33257/src/main/java/org/jenkinsci/plugins/gitclient/CliGitAPIImpl.java#L242

在 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 命令,似乎成功时输出也被丢弃。

所以看起来如果你真的需要你必须的输出

  1. 更改代码并运行修改后的版本,或者
  2. https://github.com/jenkinsci/git-client-plugin 中打开一个问题并要求他们添加配置设置以启用输出的调试日志

关于git - 如何在我的 Jenkins 控制台日志中查看构建的 git 命令输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28070560/

相关文章:

SCSS 。在本地 master 之上重新设置本地分支。如何忽略单个文件更改?

文件系统中的 Jenkins "Console Output"日志位置

c# - 如何使用 Jenkins 计算 NCover 的代码覆盖率?

jenkins - 从特定提升的构建中复制工件

Git 在推送时尝试获取 Null 提交

Git Bash 打开命令窗口

save - Jenkins:如何保存构建的变更日志

Jenkins 管道 sshPublisher : How to get exit code and output of execCommand?

Git 魔术引用

maven - Jenkins 管道未完成 tomcat war 部署