DEV Community

Saranyavenkat618
Saranyavenkat618

Posted on

Git Integration with Jenkins,Webhook

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

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

Image description

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

Image description

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

Image description

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

Image description

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

Image description

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

Image description

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

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

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

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

Image description

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

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

Image description

Top comments (0)