Git Integration with Jenkins,Webhook
Published: 2023-06-01 14:59:47

**GitHub**

GitHub is a Git-based repository host, commonly used for open-source projects. GitHub enables code collaboration, hosting, and versioning.

**Jenkins**
Jenkins is an open-source Continuous Integration and Continuous Deployment (CI/CD) tool for automating the software development life cycle (SDLC). With Jenkins testing, teams can automate the building, testing, and deploying of code. 

**Integrate GitHub + Jenkins**

A Jenkings integration with GitHub will improve the efficiency of building, testing, and deploying your code. 

The integration presented in this blog post will teach you how to schedule your build, pull your code and data files from your GitHub repository to your Jenkins machine, and automatically trigger each build on the Jenkins server after each Commit on your Git repository.

But first, let’s configure the Jenkins and GitHub integration. Let's begin with the GitHub side!

**How to Set Up the Jenkins + GitHub Integration**
Configuring GitHub

Step 1: go to your GitHub repository and click on ‘Settings’.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3bdhyoc12w98yv8zuc1e.png)

Step 2: Click on Webhooks and then click on ‘Add webhook’.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ywmawcxb0nuc534lyqyr.png)


Step 3: In the ‘Payload URL’ field, paste your Jenkins environment URL. At the end of this URL add /github-webhook/. In the ‘Content type’ select: ‘application/json’ and leave the ‘Secret’ field empty.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/umk7nlpqkhp3m47v0vx8.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lcwjr2p09z643j2qsy01.png)

Configuring Jenkins
Step 5: In Jenkins, click on ‘New Item’ to create a new project.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h4t2fbtv8brf45aovowh.png)


Step 6: Give your project a name, then choose ‘Freestyle project’ and finally, click on ‘OK’.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ho8sz035sdzrxh348jup.png)


Step 7: Click on the ‘Source Code Management’ tab.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n6o6c7iil23t80x9kbkr.png)


Step 8: Click on Git and paste your GitHub repository URL in the ‘Repository URL’ field.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/summj4l8bfsugx9v27ua.png)

Step 9: Click on the ‘Build Triggers’ tab and then on the ‘GitHub hook trigger for GITScm polling’. Or, choose the trigger of your choice.




![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ztbl8wdy5jx9v6zbblwi.png)


That's it! Your GitHub repository is integrated with your Jenkins project. With this Jenkins GitHub integration, you can now use any file found in the GitHub repository and trigger the Jenkins job to run with every code commit.

Triggering the Jenkins GitHub Integration With Every Code Commit

Step 10: Click on the ‘Build’ tab, then click on ‘Add build step’ and choose ‘Execute shell’.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7audnq0z9znb26b7xm9u.png)


Step 11: To run a Taurus test, simply use the ‘bzt’ command, followed by the name of your YML file and click on ‘Save’.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ec66xvz4bmvovpwua4f0.png)


Step 12: Go back to your GitHub repository, edit the Taurus script and commit the changes. We will now see how Jenkins ran the script after the commit.




![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/epet9yzmvn5913pfumsa.png)




![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xqot5ijg41tlmxxvbx23.png)

Step 13: Go back to your Jenkins project and you'll see that a new job was triggered automatically from the commit we made at the previous step. Click on the little arrow next to the job and choose ‘Console Output’.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qn56to6kepp790s0p2f7.png)


Step 14: You can see that Jenkins was able to pull the Taurus script and run it!


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cbase1sou6vwcbzi9r5c.png)