Jenkins CI/CD with Github with Webhooks

Creating a CI/CD pipeline using Jenkins and GitHub can be a bit involved, but I can give you an overview of the process.

  1. First, you’ll need to set up a Jenkins server. This can be done by installing Jenkins on a server or by using a cloud-based version, such as Jenkins on Azure or AWS.
  2. Next, you’ll need to install the Jenkins GitHub plugin. This plugin allows Jenkins to interact with GitHub, including the ability to trigger builds when code is pushed to a repository.
  3. Create a new Jenkins job. This job will be used to build and test the code from your GitHub repository. You can configure the job to use a build script, such as a Makefile or a Maven script, to build and test the code.
  4. In the Jenkins job configuration, you can specify the repository URL and any branches you want to build. You can also configure the build triggers, such as building on every push to the repository or on a schedule.
  5. To set up continuous deployment, you’ll need to add another step to the Jenkins job. This step can be configured to deploy the code to a staging or production environment, depending on your requirements.
  6. Go to Github, in your repository Settings , you will find an option named webhooks , you need to add the Jenkins server url and the path of the build job you created in step 3.
  7. Finally, you’ll need to set up a Jenkins service hook on the repository in Github, this will allow Github to notify Jenkins when code is pushed.

Jenkins In VPN

If you have issue like we have that Jenkins is within VPN then this section will help you. Jenkins server running on a machine within a virtual private network (VPN), there are a few things you’ll need to keep in mind when setting up the webhooks in GitHub.

  1. First, you’ll need to ensure that the Jenkins server is accessible from the public internet. This can be done by configuring the VPN to allow incoming traffic to the Jenkins server’s IP address.
  2. Next, you’ll need to make sure that the Jenkins server’s IP address is static. This is because the IP address used in the webhook configuration needs to remain the same. If the IP address changes, the webhook will no longer work.
  3. In Github, when you configure the webhook, you will need to use the public IP address or hostname of the Jenkins server. This is the address that GitHub will use to send the webhook requests.
  4. If your Jenkins server is behind a firewall, you may need to configure the firewall to allow incoming traffic on the port used by Jenkins. The default port is 8080, but this can be configured.
  5. Once you set up the webhook, you can test it by going to the repository Settings -> Webhooks and Send a test payload. It should trigger the Jenkins job
  6. Additionaly, you may want to check the system log of the Jenkins to see if the Github webhooks are being received by the Jenkins and whether they are being processed or not.

You can also use deploy keys and polling for Github integration in Jenkins which we will discuss in next post.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: