Jenkins and GIT Integration using SSH Key
Last Updated : 04 Jan, 2025
Integrating Jenkins with Git using SSH keys is a powerful way to automate your Continuous Integration (CI) and Continuous Deployment (CD) pipelines while ensuring secure access to your Git repositories. In this article, we'll guide you through the process of setting up Jenkins to work seamlessly with Git repositories using SSH keys.
Prerequisites
Jenkins is an open-source automation tool with built-in plugins for continuous integration purposes. It is used to build compile and test your project which makes developers work easy to make changes in the project. Integrating Jenkins and Git is very important if your project is on Git and you want to build it on Jenkins.
Steps to Integrate Git in Jenkins
Step 1: Click on Manage Jenkins

Step 2: Click on Global Tool Configuration

Step 3: Set your git home location i.e. give the path of git in your system

Step 4: Now that you have linked your local git with your local Jenkins. It is time to generate the SSH keys for integrating your Jenkins project with your git repository. Open your git bash and type the command
ssh-keygen
It will generate two files in .ssh folder. One is id_rsa which is the private key and the other file is id_rsa.pub

Step 5: Now go to GitHub and login with your account. Then go to settings and select the SSH and GPG keys and then click on the button New SSH Key.

Step 6: Now you have to paste the public key here which you generated and is saved in .ssh folder under the file name id_rsa.pub. Copy the whole key and paste it in git and save it there.
Adding Credentials
Add Credentials option.

Step 1: Click on the System

Step 2: Select the Global Credentials

Step 3: Then click on Add Credentials

Step 4: Select the Kind dropdown as SSH Username with Private Key and configure it. Configure the private key here which is stored in .ssh folder under the file name id_rsa.

Configuring Git with Jenkins
Now you have configured both the private and public key in Jenkins and Github respectively. Now open your project and go to configure.

Step 1: In General check the Github project and provide your Github home URL there

Step 2: Give the repository Url in Source Code Management, repository Url can be fetched by clicking on clone and download option of Github and you have to select the SSH Url. Also, add credentials there of Jenkins. Just like this image.

Step 3: Lastly set your pom.xml path if it is a maven project and click on apply and save The pom.xml will be the path of your project repository. Like if you have multiple repositories in you Github then your formal to write your pom.xml should be like this "Repo_name\pom.xml".

Now You are all set to clone the git repositories in your Jenkins. Just go to your project and select.
Similar Reads
How To Set Up Continuous Integration With Git and Jenkins? Continuous Integration (CI) is a practice where developers integrate their code into a shared repository frequently, ideally several times a day. Each integration can then be verified by an automated build and automated tests. This practice helps to detect errors quickly and improve software quality
4 min read
Integrating Jenkins With Popular GitHub When you push the code into GitHub, you have to manually trigger builds and assessments every time. It's like building a sandcastle one grain at a time. This can be time-consuming and inefficient. Fortunately, Jenkins and GitHub are a dynamic pair that can take you to a world of computerized continu
8 min read
Jenkins Interview Questions and Answer Jenkins is a popular open-source automation tool used for setting up Continuous Integration (CI) and Continuous Delivery (CD) pipelines. It helps developers automate tasks like building, testing, and deploying software, making it an essential tool for DevOps. Jenkins is known for its flexibility, sc
15+ min read
How To Integrate Jenkins With Slack ? In the present high-speed software development scene, consistent communication and collaboration efforts among teams are foremost. Jenkins, a software automation server, remains as a foundation for automating different undertakings across the product improvement lifecycle. Then again, Slack, a broad
8 min read
Integrating Ansible with GitHub for CI/CD Pipelines Many development teams face challenges when successfully combining several tools to form proper and effective CI/CD processes. An inefficient workflow means projects slow down, vary in their implementation, and have more overhead related to infrastructure management. Another consequence is that, due
8 min read