Setup SSH between Jenkins and BitBucket

In this story, you will learn how to set up SSH between Jenkins and BitBucket. Using this approach, you do not need to provide your credentials to configure the git repo in your Jenkins job, and you will achieve the password-less connection

Recently other methods have been deprecated for security reasons, and this is the new standard.

Steps

  • Generate the SSH keys
  • Copy the public key in Github
  • Configure in Jenkins Credentials
  • Configure a sample job in Jenkins using SSH connection

Configure Jenkins user

Generate the ssh keys and ensure the ssh-agent is running

ssh-keygen sudo eval $(sudo ssh-agent -s) ssh-add ~/.ssh/id_rsa An SSH key is generated successfully and allows you to achieve the password-less connection between Jenkins and BitBucket

Copy the public key using the below command (or where ever your ‘.ssh’ folder is and copy the key)

cat /home/ubuntu/.ssh/id_rsa.pub

BitBucket Configuration

Go to BitBucket repository -> setting -> SSH keys

              Configure Jenkins Credentials

Now we will configure the private key of the jenkins user in the Jenkins configuration

Add SSH Key inside Jenkins

  • Login to Jenkins
  • Now go to Manage Jenkins from the left panel inside the Jenkins console and then click Manage Credentials:
After this, select ‘Add Credentials’. This will open a new form for us. In the dropdown, select ‘SSH username with private key’ and then give a name for it.

Copy the private key from the Jenkins server.

 

Now you can clone any git repo in this Jenkins instance. You do not need to provide the credentials while configuring the job in Jenkins.

Configure Jenkins Job

  • Create a freestyle job in Jenkins
  • Configure SSH URL of your git repo
       

You may also like

November 27, 2023

Effective Remote Work: How to Enhance Your Soft Skills

Remote work, once celebrated for its conveniences like working from the comfort of home and the absence of daily commutes, can be a double-edged sword. On one side lies the allure of a familiar environment, while on the other, the potential for disconnected team members and a disjointed workflow looms.  So that’s where soft skills […]

November 6, 2023

Maximizing Your IT Internship: The Role of Mentor

When it comes to software engineering, making the leap from the classroom to the real-world industry can be a thrilling yet daunting adventure. Recent graduates navigate uncharted territory, facing complex tech challenges. They often find that practice deviates from their perception of how a task is approached and performed in the workplace. But here at […]

November 13, 2023

How Does Lilly021 Fuel Startup Success?

In today’s fast-moving business landscape, startups are pushing the boundaries of innovation and boosting our economies. However, they often wrestle with various hurdles, from limited resources to fierce competition. That’s where having the proper guidance and expertise becomes essential.  Here at Lilly021, we take pride in being that reliable partner for startups, providing the support […]