Jenkins and GIT Integration using SSH Key

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.


Contact Us