Open In App

Jenkins and GIT Integration using SSH Key

Last Updated : 18 Nov, 2025
Comments
Improve
Suggest changes
3 Likes
Like
Report

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.

Suggested Quiz
5 Questions

Which command is used to generate SSH keys for integrating Jenkins with a Git repository?

  • A

    git-init

  • B

    ssh-add

  • C

    ssh-keygen

  • D

    generate-ssh

Explanation:

SSH keys are generated using the ssh-keygen command in Git Bash.

Where should the public key (id_rsa.pub) be added for Jenkins–Git integration?

  • A

    Jenkins Global Tool Configuration

  • B

    GitHub → SSH and GPG Keys

  • C

    Jenkins Build Triggers

  • D

    Jenkins Credentials Store

Explanation:

The public key is pasted into GitHub under SSH and GPG keys to allow secure access.

When adding credentials in Jenkins for Git SSH authentication, which credential kind should be selected?

  • A

    Username and Password

  • B

    Secret Text

  • C

    SSH Username with Private Key

  • D

    API Token

Explanation:

"SSH Username with Private Key” when adding credentials.

What is the purpose of configuring the Git home location in Jenkins?

  • A

    To install Git automatically

  • B

    To link local Git with local Jenkins

  • C

    To store SSH keys

  • D

    To test Maven builds

Explanation:

Setting the Git home path allows Jenkins to recognize and use the local Git installation.

Which URL should be used in Jenkins’ Source Code Management section when configuring a Git repository?

  • A

    The HTTPS URL of the repo

  • B

    The GitHub homepage URL

  • C

    The SSH URL of the repository

  • D

    The Jenkins dashboard URL

Explanation:

Users must select the SSH URL when adding the repository to Jenkins.

Quiz Completed Successfully
Your Score :   2/5
Accuracy :  0%
Login to View Explanation
1/5 1/5 < Previous Next >

Article Tags :

Explore