GitHub + Jenkins: How to Integrate Your GitHub Repository to Your Jenkins Project
Jenkins and GitHub are two powerful tools on their own, but what about using them together? In this blog, learn about the benefits of a Jenkins integration with GitHub and how to set up the integration on your own for GitHub
What is GitHub?
GitHub is a Git-based repository host, commonly used for open-source projects. GitHub enables code collaboration, hosting, and versioning.
What is Jenkins?
Jenkins is an open-source Continuous Integration and Continuous Deployment (CI/CD) tool for automating the software development life cycle (SDLC). With Jenkins teams can automate the building, testing, and deploying of code.
How to Set Up the Jenkins + GitHub Integration
Step 1: go to your GitHub repository and click on ‘Settings’.
Step 2: Click on Webhooks and then click on ‘Add webhook’.
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 and click on “Add webhook”.
We’re done with the configuration on GitHub’s side! Now let’s move on to Jenkins.
Configuring Jenkins
Step 4: In Jenkins, click on ‘New Item’ to create a new project.
Step 5: Give your project a name, then choose ‘Freestyle project’ and finally, click on ‘OK’.
Step 6: Click on the ‘Source Code Management’ tab.
Step 7: Click on Git and paste your GitHub repository URL in the ‘Repository URL’ field.
Step 8: Click on the ‘Build Triggers’ tab and then on the ‘GitHub hook trigger for GITScm polling’. Or, choose the trigger of your choice.
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 GitHub Jenkins Integration With Every Code Commit
Step 9: Click on the ‘Build’ tab, then click on ‘Add build step’ and choose ‘Execute shell’.
Step 10: Here we are running simple shell script to print text.
Step 11: Go back to your GitHub repository, edit the your script and commit the changes. We will now see how Jenkins ran the script after the commit.
Step 12: 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’.
Step 13: You can see that Jenkins was able to pull the Taurus script and run it!
Conclusion:
Congratulations! You have now set up a fully functioning Jenkins GitHub integration. Every time you publish your changes to GitHub, your newly set up GitHub-Jenkins integration will trigger your latest Jenkins job.
If you have any questions or feedback, feel free to leave a comment below. Keep practicing and Happy Learning 🎉.
“Together we can achieve great things. Let’s collaborate and make a difference.”
Connect with me 😎