Jenkins/Docker Project Key points — part 3
Set up a GitHub repository for code deployment and create a webhook to connect with the Jenkins server
In the GitHub Key Points series, we have covered essential topics such as pulling, pushing, branching, and merging code in GitHub. In this chapter, we will delve into the branching strategy utilized for our project. However, before we proceed, let’s take a moment to understand what branching strategies are, their significance, and how we determine the most suitable strategy to employ.
A branching strategy is a set of rules that developers follow when they write, merge, and deploy shared code to a central repository. It aids easy collaboration among developers, helps avoid merging mistakes, and resolves issues such as feature prioritization, bug fixes, and release management.
There are four major branching strategies: GitFlow, GitHub Flow, GitLab Flow, and Trunk-based development. We will be using the GitHub Flow method for this project. GitHub Flow is a much simpler branching strategy and is suitable for the app that we will deploy. There is a main branch where the code is stored, but every new change branches off into a new feature or hotfix branch. After the changes are tested and approved, they are merged back into the main branch. This way, the main branch is constantly in a deployable state, and it supports the CI/CD process.
Here is a link to the GitHub source code repository.
The repository contains the application source code, Jenkins pipeline Groovy script, Dockerfile, and pom.xml file.
After code is pushed to GitHub, it typically undergoes a peer review process and, upon approval, is merged into the main branch. Subsequently, a webhook is triggered to initiate the Jenkins CI/CD pipeline job.
Webhooks serve as triggers that prompt GitHub to send an HTTP POST payload to a designated URL. In this scenario, when code is merged into the main branch, it triggers a signal to the Jenkins server, instructing it to commence the CI/CD pipeline. It’s worth noting that the payload URL for this setup is the IP address or hostname of your Jenkins server, followed by the default port and the ‘/github-webhook/’ endpoint.
Visit GitHub doc for more information on webhooks.