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

Git plugin global config incorrectly reports git not in PATH

    • Jenkins 2.232

      The git client plugin global configuration section allows the user to define git implementations which are then used as tools. One of the fields is "Path". When that field has the simple name 'git', it should find command line git on the system path.

      The error message reports that git cannot be found on the path, yet git works great on that machine and is definitely found on the path.

      Users may continue to use command line git in this configuration, they can ignore the incorrect warning message from the dialog.

          [JENKINS-61711] Git plugin global config incorrectly reports git not in PATH

          Rishabh Budhouliya added a comment - - edited

          Hi markewaite. I was trying to reproduce this bug and I can't figure out a way to do it. I'd like to know if this is a windows or a linux machine.

          As it can be seen, the environment variable PATH is being used to find the git executable and depending upon the OS, it will try to append PATH + "git" and try to check if that exists. Since you have mentioned that the git executable does exist on the path, it doesn't make sense to me how could the FormValidation validateExecutable can't find it.

          Rishabh Budhouliya added a comment - - edited Hi markewaite . I was trying to reproduce this bug and I can't figure out a way to do it. I'd like to know if this is a windows or a linux machine. As it can be seen, the environment variable PATH is being used to find the git executable and depending upon the OS, it will try to append PATH + "git" and try to check if that exists. Since you have mentioned that the git executable  does exist on the path, it doesn't make sense to me how could the FormValidation validateExecutable can't find it.

          Mark Waite added a comment - - edited

          rishabhbudhouliya thanks very much for investigating and for trying to duplicate the problem. I should have provided a precise set of steps that will duplicate the problem. The steps are:

          1. Install and enable the git LFS extension (if not already installed)
          2. Install Docker
          3. Clone my docker-lfs repository
            $ git clone https://github.com/MarkEWaite/docker-lfs.git
          4. Change to the cloned directory
            $ cd docker-lfs
          5. Checkout the lts branch
            $ git checkout -b lts -t origin/lts
          6. Remove the master branch
            $ git branch -D --delete master
          7. Checkout the lts-with-plugins branch
            $ git checkout -b lts-with-plugins -t origin/lts-with-plugins
          8. Build the lts-with-plugins image
            $ ./docker_build.py
          9. Run the lts-with-plugins image
            $ ./docker_run.py --clean --quiet
          10. Open the newly started Jenkins in a web browser on port 8080
          11. Open "Manage Jenkins"
          12. Open "Global Tool Configuration"
          13. Scroll down to show the git tool configuration
          14. Wait briefly while Jenkins checks for existence of the git tool, note that there is a red warning below that field which reports the tool is not available

          Mark Waite added a comment - - edited rishabhbudhouliya thanks very much for investigating and for trying to duplicate the problem. I should have provided a precise set of steps that will duplicate the problem. The steps are: Install and enable the git LFS extension (if not already installed) Install Docker Clone my docker-lfs repository $ git clone https://github.com/MarkEWaite/docker-lfs.git Change to the cloned directory $ cd docker-lfs Checkout the lts branch $ git checkout -b lts -t origin/lts Remove the master branch $ git branch -D --delete master Checkout the lts-with-plugins branch $ git checkout -b lts-with-plugins -t origin/lts-with-plugins Build the lts-with-plugins image $ ./docker_build.py Run the lts-with-plugins image $ ./docker_run.py --clean --quiet Open the newly started Jenkins in a web browser on port 8080 Open "Manage Jenkins" Open "Global Tool Configuration" Scroll down to show the git tool configuration Wait briefly while Jenkins checks for existence of the git tool, note that there is a red warning below that field which reports the tool is not available

          Mark Waite added a comment -

          rishabhbudhouliya I was concerned that the problem might be specific to my Docker image, so I tested a fresh download of Jenkins 2.222.1 run as a war file on my Ubuntu 18.04 computer. Steps in this test were:

          1. Download Jenkins 2.222.1 war file
            $ wget http://mirrors.jenkins.io/war-stable/2.222.1/jenkins.war
          2. Run war file
            $ java -jar jenkins.war
          3. Connect to the Jenkins instance on port 8080 with a web browser
          4. Enter the random admin password for Jenkins
          5. Create a user account in Jenkins
          6. Choose to install selected plugins from the install wizard, select "None", then select only the git plugin
          7. Complete the install wizard, watch the plugins as they install
          8. Open "Manage Jenkins" and the "Global Tool Configuration" page
          9. Review the "git" configured for the Default git tool, confirm that it reports that "git" cannot be found, even though there is a git installed in /usr/bin on my computer

          Thanks again for investigating!

          Mark Waite added a comment - rishabhbudhouliya I was concerned that the problem might be specific to my Docker image, so I tested a fresh download of Jenkins 2.222.1 run as a war file on my Ubuntu 18.04 computer. Steps in this test were: Download Jenkins 2.222.1 war file $ wget http://mirrors.jenkins.io/war-stable/2.222.1/jenkins.war Run war file $ java -jar jenkins.war Connect to the Jenkins instance on port 8080 with a web browser Enter the random admin password for Jenkins Create a user account in Jenkins Choose to install selected plugins from the install wizard, select "None", then select only the git plugin Complete the install wizard, watch the plugins as they install Open "Manage Jenkins" and the "Global Tool Configuration" page Review the "git" configured for the Default git tool, confirm that it reports that "git" cannot be found, even though there is a git installed in /usr/bin on my computer Thanks again for investigating!

          Rishabh Budhouliya added a comment - - edited

          Many thanks for laying out the steps so clearly, I was able to reproduce the bug and I think I have found the problem.

          https://github.com/jenkinsci/jenkins/blob/d66bd8595e531749e842274a806eabab5cc16a32/core/src/main/java/hudson/util/DOSToUnixPathHelper.java#L68

          Here, the executable file is built as "_dir + File.pathSeperator + exe" where File.pathSeperator should be used for multiple directories (: for Unix, ; for windows). 

          For example, it was trying to find git executable in "/usr/local/bin:git" instead of "/usr/local/bin/git"

          I changed it to File.seperator (platform independent, "/" for Unix) and it is working correctly, here is a screenshot of my Jenkins UI:

          Rishabh Budhouliya added a comment - - edited Many thanks for laying out the steps so clearly, I was able to reproduce the bug and I think I have found the problem. https://github.com/jenkinsci/jenkins/blob/d66bd8595e531749e842274a806eabab5cc16a32/core/src/main/java/hudson/util/DOSToUnixPathHelper.java#L68 Here, the executable file is built as "_dir + File.pathSeperator + exe" where File.pathSeperator should be used for multiple directories (: for Unix, ; for windows).  For example, it was trying to find git executable in "/usr/local/bin:git" instead of "/usr/local/bin/git" I changed it to File.seperator (platform independent, "/" for Unix) and it is working correctly, here is a screenshot of my Jenkins UI:

          Mark Waite added a comment - - edited

          Thanks for that research and for finding the root of the problem. Will you submit a pull request with a fix and with tests to confirm that the fix is working as expected?

          Since the issue seems to be in Jenkins core, I've reassigned the component as core.

          Mark Waite added a comment - - edited Thanks for that research and for finding the root of the problem. Will you submit a pull request with a fix and with tests to confirm that the fix is working as expected? Since the issue seems to be in Jenkins core, I've reassigned the component as core .

          Sure, I'll raise a pull request with the fix and tests.

          Rishabh Budhouliya added a comment - Sure, I'll raise a pull request with the fix and tests.

          I have raised a pull request: https://github.com/jenkinsci/jenkins/pull/4653 
          Thanks.

          Rishabh Budhouliya added a comment - I have raised a pull request:  https://github.com/jenkinsci/jenkins/pull/4653   Thanks.

            rishabhbudhouliya Rishabh Budhouliya
            markewaite Mark Waite
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: