【问题标题】:wrapper for git, for jenkins pipeline, on windows 10 jenkins slave用于 git 的包装器,用于詹金斯管道,在 Windows 10 詹金斯奴隶
【发布时间】:2021-12-31 14:20:45
【问题描述】:

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

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

"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 包装脚本。有什么建议吗,伙计们?

【问题讨论】:

    标签: windows git batch-file jenkins-pipeline jenkins-git-plugin


    【解决方案1】:

    Git 插件使用String getGitExe() 返回builtOn 节点的git exe,通常为“Default”或“jgit”。

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


    Wojtas.Zet 确认在the comments:

    我查看了 git-plugin 的源代码,发现有一种方法可以在 jenkins 节点 GUI 中定义自定义 git 可执行文件

    我在 Jenkins GUI - Jenkins ---> Nodes ---> NodeA (Node properties ---> Tool Locations ---> List of tool locations) 中点击了它

    【讨论】:

    • 您好 VonC,感谢您的提示。我查看了 git-plugin 的源代码,并意识到有一种方法可以在 jenkins 节点 GUI 中定义自定义 git 可执行文件。这成功了,终于奏效了。
    • @Wojtas.Zet 太好了!你有说明这一点的源代码文件的 URL 吗?
    • 我仍在努力将它包含在源代码中。目前我在 Jenkins GUI - Jenkins ---> Nodes ---> NodeA (Node properties ---> Tool Locations ---> List of tool locations) 中单击了它。还不知道如何在管道中编写它。也许options {} 或node {} 块?
    • 这里是图片链接:ibb.co/f9kN23b
    • @Wojtas.Zet 感谢您的反馈。我已将您的评论和插图包含在答案中以提高知名度。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-11
    • 1970-01-01
    • 2015-07-25
    • 1970-01-01
    • 2018-08-02
    • 2018-04-30
    相关资源
    最近更新 更多