Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-28943

Windows git cannot clone ssh repo if Git is referenced from cmd directory and is in a non-default location

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • git-client-plugin
    • Windows 2k8 R2 SP1. Git-1.9.5-preview20150319, jenkins-1.617, git plugin: 2.3.5, git client plugin: 1.17.1

      Hello,

      I have installed msysgit under D:\git-1.9.5\Git. git.exe and ssh.exe are available in command prompt

      C:\Users\Administrator>git --version
      git version 1.9.5.msysgit.1

      C:\Users\Administrator>ssh -V
      OpenSSH_6.6.1p1, OpenSSL 1.0.1m 19 Mar 2015

      As I understood from the following error message

      Started by user Administrator
      Building in workspace D:\jenkins\jobs\test\workspace
       > D:\git-1.9.5\Git\cmd\git.exe rev-parse --is-inside-work-tree # timeout=10
      Fetching changes from the remote Git repository
       > D:\git-1.9.5\Git\cmd\git.exe config remote.origin.url ssh://git@gitlab.example.net.org/test/test.git # timeout=10
      Fetching upstream changes from ssh://git@gitlab.example.net.org/test/test.git
       > D:\git-1.9.5\Git\cmd\git.exe --version # timeout=10
      using GIT_SSH to set credentials gitlab deploy key
      FATAL: ssh executable not found. The git plugin only supports official git client http://git-scm.com/download/win
      java.lang.RuntimeException: ssh executable not found. The git plugin only supports official git client http://git-scm.com/download/win
      	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.getSSHExecutable(CliGitAPIImpl.java:1531)
      	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.createWindowsGitSSH(CliGitAPIImpl.java:1537)
      	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:1300)
      	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$300(CliGitAPIImpl.java:86)
      	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:324)
      	at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:733)
      	at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:983)
      	at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1016)
      	at hudson.scm.SCM.checkout(SCM.java:485)
      	at hudson.model.AbstractProject.checkout(AbstractProject.java:1282)
      	at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:610)
      	at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:86)
      	at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:532)
      	at hudson.model.Run.execute(Run.java:1744)
      	at hudson.model.
      FreeStyleBuild.run(FreeStyleBuild.java:43)
      	at hudson.model.ResourceController.execute(ResourceController.java:98)
      	at hudson.model.Executor.run(Executor.java:374)
      Finished: FAILURE
      

      The plugin could not find the ssh.exe. Maybe related issue - https://issues.jenkins-ci.org/browse/JENKINS-21030 but as I can see the issue has been resolved.

          [JENKINS-28943] Windows git cannot clone ssh repo if Git is referenced from cmd directory and is in a non-default location

          Mark Waite added a comment - - edited

          The plugin is regularly tested on Windows systems with git installed in a non-default location. One of my test machines has git installed on the D: drive. I believe another test machine has it installed in a different non-default location.

          You may be able to diagnose why it can't find ssh.exe in your case by reviewing the steps the source code currently takes to find ssh.exe on Windows.

          The steps used to attempt to locate the correct ssh.exe include:

          • If the GIT_SSH environment variable exists and names a file which exists, use that name (allows user override)
          • If %ProgramFiles%\git\bin\ssh.exe exists, use that name (32 bit windows default location)
          • If %ProgramFiles(x86)%\git\bin\ssh.exe exists, use that name (64 bit windows default location)
          • If the git program name provided by the user is an absolute path, and if an ssh.exe is in the same directory as that program, use ssh.exe in that directory
          • If the git program is in the "cmd" directory instead of the "bin" directory, look in the "bin" directory adjacent to the "cmd" directory

          Some possible places where that will go wrong include:

          • git not in the PATH (can't find git program, thus can't find ssh near it)
          • git.exe in a directory that is early on the path without an ssh.exe in the same directory

          Based on the "D:\git-1.9.5\Git\cmd\git.exe" in the bug report (thanks for including it), I assume the last stage of the "find ssh.exe" process must be failing your environment.

          Does the behavior improve if you use D:\git-1.9.5\Git\bin\git.exe as the git executable instead?

          Mark Waite added a comment - - edited The plugin is regularly tested on Windows systems with git installed in a non-default location. One of my test machines has git installed on the D: drive. I believe another test machine has it installed in a different non-default location. You may be able to diagnose why it can't find ssh.exe in your case by reviewing the steps the source code currently takes to find ssh.exe on Windows. The steps used to attempt to locate the correct ssh.exe include: If the GIT_SSH environment variable exists and names a file which exists, use that name (allows user override) If %ProgramFiles%\git\bin\ssh.exe exists, use that name (32 bit windows default location) If %ProgramFiles(x86)%\git\bin\ssh.exe exists, use that name (64 bit windows default location) If the git program name provided by the user is an absolute path, and if an ssh.exe is in the same directory as that program, use ssh.exe in that directory If the git program is in the "cmd" directory instead of the "bin" directory, look in the "bin" directory adjacent to the "cmd" directory Some possible places where that will go wrong include: git not in the PATH (can't find git program, thus can't find ssh near it) git.exe in a directory that is early on the path without an ssh.exe in the same directory Based on the "D:\git-1.9.5\Git\cmd\git.exe" in the bug report (thanks for including it), I assume the last stage of the "find ssh.exe" process must be failing your environment. Does the behavior improve if you use D:\git-1.9.5\Git\bin\git.exe as the git executable instead?

          >Does the behavior improve if you use D:\git-1.9.5\Git\bin\git.exe as the git executable instead?
          Yeap, if I specify D:\git-1.9.5\Git\bin\git.exe all works fine.

          But as you told before - "If the git program is in the "cmd" directory instead of the "bin" directory, look in the "bin" directory adjacent to the "cmd" directory"

          It seems that rule doesn't work or did I miss something?

          Alex Domoradov added a comment - >Does the behavior improve if you use D:\git-1.9.5\Git\bin\git.exe as the git executable instead? Yeap, if I specify D:\git-1.9.5\Git\bin\git.exe all works fine. But as you told before - "If the git program is in the "cmd" directory instead of the "bin" directory, look in the "bin" directory adjacent to the "cmd" directory" It seems that rule doesn't work or did I miss something?

          Mark Waite added a comment - - edited

          You're right. I confirmed with my Windows Home Server 2011 machine (D: installed git) that if I set the git installation on that machine to the "cmd" directory, then the plugin cannot find ssh.

          I'm evaluating a possible fix. The change resolved the problem on my Windows 2011 Home Server and seems low risk (Windows only, code is only executed when other attempts to locate the executable have failed).

          Mark Waite added a comment - - edited You're right. I confirmed with my Windows Home Server 2011 machine (D: installed git) that if I set the git installation on that machine to the "cmd" directory, then the plugin cannot find ssh. I'm evaluating a possible fix . The change resolved the problem on my Windows 2011 Home Server and seems low risk (Windows only, code is only executed when other attempts to locate the executable have failed).

          Code changed in jenkins
          User: Mark Waite
          Path:
          src/main/java/org/jenkinsci/plugins/gitclient/CliGitAPIImpl.java
          http://jenkins-ci.org/commit/git-client-plugin/3e5ad16623e5583444298a5e9adee9c3bb230157
          Log:
          [Fix JENKINS-28943] Find windows ssh even if git is absolute path to cmd dir

          The path guesser in getPathToExe correctly checks for cmd and exe
          suffixes, and correctly checks each entry in the PATH environment
          variable. Prior to this change, it did not check for the absolute
          path having been specified with the cmd directory rather than the bin
          directory.

          The user had set C:\Program Files\Git\cmd\git.exe as the git program
          for that slave. That is an allowed setting, and it executed most git
          commands correctly. It failed on ssh based commands.

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Mark Waite Path: src/main/java/org/jenkinsci/plugins/gitclient/CliGitAPIImpl.java http://jenkins-ci.org/commit/git-client-plugin/3e5ad16623e5583444298a5e9adee9c3bb230157 Log: [Fix JENKINS-28943] Find windows ssh even if git is absolute path to cmd dir The path guesser in getPathToExe correctly checks for cmd and exe suffixes, and correctly checks each entry in the PATH environment variable. Prior to this change, it did not check for the absolute path having been specified with the cmd directory rather than the bin directory. The user had set C:\Program Files\Git\cmd\git.exe as the git program for that slave. That is an allowed setting, and it executed most git commands correctly. It failed on ssh based commands.

          Mark Waite added a comment -

          Included in git client plugin 1.18.0 released 18 July 2015

          Mark Waite added a comment - Included in git client plugin 1.18.0 released 18 July 2015

          Code changed in jenkins
          User: Mark Waite
          Path:
          src/main/java/org/jenkinsci/plugins/gitclient/CliGitAPIImpl.java
          src/test/java/org/jenkinsci/plugins/gitclient/CliGitAPIImplTest.java
          src/test/java/org/jenkinsci/plugins/gitclient/GitAPITestCase.java
          http://jenkins-ci.org/commit/git-client-plugin/2a2c6d339dcda8556b267f8a3584a5dd762be387
          Log:
          Add mingw64 dir to ssh location guesser - windows git 2.8.0

          Implement ssh executable test in CliGitAPIImplTest, not applicable
          to JGit.

          May help JENKINS-30045, JENKINS-28943, JENKINS-25297, & JENKINS-21806

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Mark Waite Path: src/main/java/org/jenkinsci/plugins/gitclient/CliGitAPIImpl.java src/test/java/org/jenkinsci/plugins/gitclient/CliGitAPIImplTest.java src/test/java/org/jenkinsci/plugins/gitclient/GitAPITestCase.java http://jenkins-ci.org/commit/git-client-plugin/2a2c6d339dcda8556b267f8a3584a5dd762be387 Log: Add mingw64 dir to ssh location guesser - windows git 2.8.0 Implement ssh executable test in CliGitAPIImplTest, not applicable to JGit. May help JENKINS-30045 , JENKINS-28943 , JENKINS-25297 , & JENKINS-21806

            ndeloof Nicolas De Loof
            alex_hha Alex Domoradov
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: