windowsgitbatch-filejenkins-pipelinejenkins-git-plugin

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


What I am trying to accomplish - I want to have a wrapper for git itself, that will retry if the git command fails (timeout/network issue).

I have following dummy code of wrapper:

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

After changing $PATH and saving the file as git.cmd and removing path to git.exe it works well if I call any git command directly from jenkins:

script {
        bat 'git clone %REPO%'
       }

result:

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

However I want it to work for multibranch pipeline, which uses jenkins git plugin https://github.com/jenkinsci/git-plugin/blob/master/README.adoc

And running checkout with this plugin results in:

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

Somehow the git plugin knows, it is missing the git.exe and it is not picking up the git.cmd wrapper script as in the first example. Any suggestions, Guys?


Solution

  • The Git Plugin uses String getGitExe() which returns the git exe for builtOn node, often "Default" or "jgit".

    So check first, as in "Relevance of specifying Tool Locations in Jenkins Node Configuration", if you can specify the full path of your git.cmd wrapper in the Git (Default) field of your node (agent) tool configuration.


    The Wojtas.Zet confirms in the comments:

    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)

    Node properties