git 的包装器,用于 jenkins 管道,在 windows 10 jenkins slave 上

wrapper for git, for jenkins pipeline, on windows 10 jenkins slave

我想要完成的事情 - 我想要一个 git 本身的包装器,如果 git 命令失败(timeout/network 问题),它将重试。

我有以下包装器的虚拟代码:

"C:\Program Files\Git\cmd\git.exe" %*
echo Success!

更改 $PATH 并将文件另存为 git.cmd 并删除 git.exe 的路径后,如果我直接从 jenkins 调用任何 git 命令,效果很好:

script {
        bat 'git clone %REPO%'
       }

结果:

(...)
Updating files: 100% (5314/5314), done.
17:58:51 E:\jenkins\workspace\sandbox>echo Success! 
17:58:51 Success!

但是我希望它适用于使用 jenkins git 插件 的多分支管道 https://github.com/jenkinsci/git-plugin/blob/master/README.adoc

并且 运行 使用此插件签出结果:

18:48:46  Caused by: java.io.IOException: Cannot run program "git" (in directory "E:\jenkins\workspace\PR-XXXX"): CreateProcess error=2, The system cannot find the file specified

不知何故 git 插件知道,它缺少 git.exe 并且它没有像第一个示例那样获取 git.cmd 包装器脚本。伙计们,有什么建议吗?

Git 插件使用 String getGitExe(),其中 returns git 用于内置节点的 exe,通常是“Default”或“jgit ".

所以首先检查,如“Relevance of specifying Tool Locations in Jenkins Node Configuration”,如果您可以在节点(代理)工具配置的 Git (Default) 字段中指定 git.cmd 包装器的完整路径.


Wojtas.Zet confirms in :

I looked the source code of git-plugin and realized there is a way to define custom git executable in the jenkins node GUI

I have clicked it in Jenkins GUI - Jenkins ---> Nodes ---> NodeA (Node properties ---> Tool Locations ---> List of tool locations)