Wednesday, June 30, 2021

How to Integrate Jenkins and GitHub using SSH keys? | Jenkins and GitHub Integration

We will see how to connect to GitHub from Jenkins using SSH keys instead of using user name and password. It is also a good practice to use SSH keys in Jenkins jobs instead of using user name and password.


Watch the steps in YouTube channel:

Pre-requistes:

  • Jenkins is up and running
  • Credentials plug-in installed in Jenkins

Create SSH keys in your Jenkins EC2 instance

ssh-keygen

enter four times. this will create keys in .ssh folder.

Copy and paste the public key
sudo cat ~/.ssh/id_rsa.pub

Add public Keys into your respective GitHub

Add public keys into your Repository--> settings--> Deploy keys section




Click on Add Deploy Key and enter public keys and save.

Add Private Keys in Jenkins Master
Login Jenkins. Go to Manage Jenkins. click on Credentials



Click on Jenkins


Click on Global Credentials



Click on Add Credentials


Choose SSH username with private key






Choose SSH username with private key
username can be anything
Click on enter directly under private key option and Click Add


Copy and paste private key(not public key) of your from Jenkins instance. command is below:
sudo cat ~/.ssh/id_rsa

copy the content of whole output from above command.
Click OK to save.

Now go to any Jenkins Job, you can choose this option for checking out from GitHub. Make sure you enter SSH url not https url.




That's it. This is how you use SSH url and private keys to checkout code from bitbucket or Github without entering username/password in Jenkins.



1 comment:

  1. JavaScript is among the most favorable programming languages to learn for hobby projects and career/job perspectives. Make friends with JavaScript and advance your career as a JS developer. Either you are learning JavaScript afresh or brushing up your programming skills, you will find these ten hottest online JavaScript courses worth your time, effort, and money. free Oracle database courses

    ReplyDelete