Configuring Git in Jenkins
Jenkins can be with many source repositories, and Git is one of them. Let's consider the case of an application that is Java-based and the source code is stored in Git, Gitlab, and/or GitHub.
We need to tell Jenkins where Git is installed in the local system.
Getting ready
Download the required Git version based on the operating system, or install automatically.
How to do it...
- Open the Jenkins dashboard.
- Go to
Manage Jenkins
. - Go to
Global Tool Configuration
to configure the tools, their locations, and automatic installers. - Go to the
Git
section. - Give the
Name
and click onInstall Automatically
, or provide a path to Git. - You can add multiple Gits based on the version or for the specific agent. You need to give a meaningful name so it can be identified easily while configuring the build job:

How it works...
When you create a build job in Jenkins and configure it, you need to specify the Git version that will be used by the build execution. You can use existing Git installation available on the system as well if you don't want to install automatically.
In the Source Code Management
section, select the appropriate Git that is configured in Global Tool Configuratio
n from the list.
Go to the Git executable configuration to change the Git installable.