Environment
-
CloudBees CI (CloudBees Core) on modern cloud platforms - Managed controller
-
CloudBees CI (CloudBees Core) on modern cloud platforms - Operations Center
-
CloudBees CI (CloudBees Core) on traditional platforms - Client controller
-
CloudBees CI (CloudBees Core) on traditional platforms - Operations Center
-
Git plugin
Resolution
Jenkins allows for multiple configurations of git
for the Jenkins instance and in the agents. You may encounter errors using different paths for the Git executable in Jenkins and Agents, such as the following:
[poll] Last Built Revision: Revision XXXXXXXXX (refs/remotes/origin/master) using credential XXXXXXXXX > /usr/local/git/bin/git --version # timeout=10 > /usr/local/git/bin/git --version # timeout=10 using GIT_ASKPASS to set credentials XXXXXXXXX Credentials > /agent/git/path/git ls-remote -h https://repositoryURL.git # timeout=10 FATAL: hudson.plugins.git.GitException: Error performing command: /agent/git/path/git ls-remote -h https://repositoryURL.git java.io.IOException: error=2, No such file or directory at java.lang.UNIXProcess.forkAndExec(Native Method) ...
In this case, this error appears during the polling action, and the polling is never performed. Nevertheless, if we run a manual build, it will work fine.
To avoid these kinds of issues, we can set a specific configuration where we will set the git executable file path in the $PATH
environment variable, and we will set a relative path (using only the git
command) for the git installations
.
To fix this, perform the following steps for using the $PATH
environment variable in the git installation
:
Adding Git executable to the $PATH environment variable in the Jenkins instance
First, we will need to add the Git
executable to the $PATH
environment variable in the Jenkins instance. This process depends on the OS we have:
Adding Git executable to the $PATH environment variable in Linux or Unix based OS
If we are running the Jenkins instance over a Linux OS or Mac OS or based on Unix OS, we will need to perform the following steps for adding the Git executable to the $PATH
environment variable:
-
Login into the machine where the Jenkins instance is hosted as the same user who runs the Jenkins instance.
-
Check if the git installation is included in the current
$PATH
environment variable running the following command in a terminal:
git --version
-
An output like the following will mean that we have one git installation included in the
$PATH
environment variable.
git version 2.17.1
Additionally, we can check if this Git installation is the correct installation using the following command:
which git
If the output of the previous command is the path where the Git installation is located (which is the one you want to use), then you could go to the next step [#configuringgitexecutableinthejenkinscontroller]. Otherwise, it means you have more than one Git installation in your machine, and you may face some issues if you switch the Git installation in the path. Go to [#impossibletousepathenvironmentvariablewhatcanido]
In the other case, output like the following will mean that you don’t have one Git installation included in the $PATH
environment variable, and you can add it.
bash: git: command not found
-
For adding the Git installation to the
$PATH
environment variable, you only need to add the following line to the appropriate file that will be read when your shell is launched. There are a few different places where you could conceivably set the variable name: ~/.bash_profile, ~/.bashrc, etc. Please contact a more suitable team to know the best file to add theexport
line.
export PATH=$PATH:/place/with/the/file
Where /place/with/the/file
is the path to the Git installation.
-
Once you performed this change, you can log in again in your system and check it running the
git --version
command and thewhich git
command. -
Jenkins will need to be restarted for the
PATH
environment variable change to be reflected in Jenkins.
Adding Git executable to the %PATH% environment variable in Windows OS
If we are running the Jenkins instance on Windows OS, we will need to perform the following steps for adding the Git executable to the %PATH%
environment variable:
-
Login into the machine where the Jenkins instance is hosted as the same user who runs the Jenkins instance.
-
Check if the git installation is included in the
%PATH%
environment variable running the following command in a PowerShell or CMD terminal:
git --version
-
An output like the following will mean that we have one git installation included in the
%PATH%
environment variable.
git version 2.27.0.windows.1
Additionally, We can check if this Git installation is the correct installation using the following commands:
where.exe git
If the output of the previous command is the path where the Git installation, which you want to use, is located, then you could go to the next step [#configuringgitexecutableinthejenkinscontroller]. Otherwise, it means you have more than one Git installation in your machine, and you may face some issues if you switch the Git installation in the path. Go to [#impossibletousepathenvironmentvariablewhatcanido]
In the other case, output like the following will mean that you don’t have one Git installation included in the %PATH%
environment variable, and you can add it.
bash: git: command not found
-
For adding the Git installation to the
%PATH%
environment variable, you will need to navigate toEdit the system environment variables
window inside theControl Panel
. Click in theEnvironment Variable...
. Double-Click over thePath
variable and add the path of the Git installation binary to thePath
variable. Remember, you have twoPath
variables. You will need to choose the right one depending on your requirements (thePath
variable inside theUser Variables for ...
section will affect only to the current user; and thePath
variable inside theSystem variables
section will affect to all users on the Windows machine). Please, contact a more suitable team for choosing the bestPath
variable to add the path of the Git installation binary. -
Once you performed this change, you can login again in your system and check it running the
git --version
command and thewhere.exe git
command in a terminal.
Adding Git executable to the $PATH environment variable in the agents
For adding the Git executable path to the $PATH
environment variable in the agents, we will need to follow the same steps of the [#addinggitexecutabletothepathenvironmentvariableinthejenkinsinstance], but running all commands in the agent machines.
Configuring Git executable in the Jenkins controller
Once the Git installation binary is correctly included in the $PATH
environment variable of all machines of your system (Jenkins controller and agents) is time to modify the git configuration of your Jenkins instance.
-
Login into the Jenkins instance as an administrator.
-
Go to
Manage Jenkins
->Global Tool Configuration
->Git
->Git installations
-
Type
git
in thePath to Git executable
of each Git installation where you want to use the Git installation binary included in the$PATH
environment variable.
Impossible to use the $PATH environment variable. What can I do?
Sometimes, we can’t configure a specific Git installation binary in the $PATH
environment variable due to some situations: a multiple git installation in the agent or controller machines; multiples git versions in the same machine; etc.
In this case, we will need to be more specific, setting the git path in each system, and we will not use the $PATH
environment variable. Initially, we have three locations where we can change the git configuration inside the Jenkins instance:
In the Global Tool Configuration
In Manage Jenkins
-> Global Tool Configuration
-> Git
-> Git installations
we can add and edit any Git installation, setting the Path to Git executable
. Here, we can leave the Install automatically
checkbox unchecked, and each time Jenkins uses this git installation, it will search for the Git binary in the Path to Git executable
folder wherever this Git installation is used (in the agent or the controller). Therefore, we can face some issues if we have a different path of the Git executable in the controller and the agent.
In the node configurations
In Manage Jenkins
-> Manage Nodes
, we can modify the Git binary path for each Git installation (added in the Global Tool Configuration
section). Once we are in Manage Nodes
, we can click over Configure
for each agent. Inside the Configuration
page of the agent, we can check the Tool Locations
checkbox and add a new location for the specific Git installation.

Where:
-
Name: the git installation that you want to change the Git binary location.
-
Home: the path of the Git installation binary on this agent machine.
In the job configuration
You can choose which Git installation to use in the Job configuration or the Pipeline code. The steps to configure this are: gitTool and https://plugins.jenkins.io/git/#configuration