Tuesday, August 29, 2023

Integrate Jenkins with Github

 GIT and Jenkins


Install Git plugin and GitHub plugin on Jenkins, in my case the jenkins login url is http://localhost:8080

Click on Manage Jenkins -> Manage Plugins -> search for Git plugin and GitHub plugin and install it
Integrate Jenkins with Github:

Login to GitHub and get the Project and Repository URL. In my case

Project URL: https://github.com/yashwanthsn2020/automation/


Repository URL: https://github.com/yashwanthsn2020/automation.git


Create a new job in jenkins -> jenkins-git-integration -> Freestyle project -> click OK

On the General tab -> choose GitHub project and add the Project URL

Under Source Code Management -> choose Git and add Repository URL

Branches to build: by default it will be master branch, you can add other branches 

Under Build Triggers section I chose Build Periodically since my jenkins run on localhost. 

I.e, http://localhost:8080, we can not add a webhook from GitHub to jenkins for a localhost

If Jenkins is not on localhost, you can choose "GitHub hook trigger for GITScm polling"
Click on Save and -> Back to Dashboard -> choose the job -> Jenkins-git-integration -> click on Build Now

Here is the console output from Jenkins
If you choose GitHub hook trigger for GITScm polling under Build Triggers, then you have to login to GitHub -> Settings -> Webhooks -> Add webhook
Click on Add webhook