This tutorial aims to provide you with a step-by-step guide on how to integrate GitHub with a continuous integration/continuous deployment (CI/CD) service, in our case, Jenkins.
By the end of this tutorial, you will be able to:
Continuous Integration (CI) is a development practice that involves developers integrating code into a shared repository frequently. Each integration can then be verified by an automated build and automated tests.
Continuous Deployment (CD) is a software release process that uses automated testing to validate if changes to a codebase are correct and stable for immediate autonomous deployment to a production environment.
Install Jenkins: Follow the official Jenkins installation guide.
Create a New Job in Jenkins: Navigate to the Jenkins dashboard and click on New Item
. Choose Freestyle project
and provide a name for your job.
Configure GitHub in Jenkins: Under the Source Code Management
section, select Git
and enter your GitHub repository URL.
Webhooks allow you to build or set up integrations that subscribe to certain events on GitHub.com.
Navigate to your GitHub repository, click on Settings
> Webhooks
> Add webhook
.
Set Payload URL
to your Jenkins environment followed by /github-webhook/
(e.g., http://your-jenkins-url/github-webhook/
).
Choose Content type
as application/json
.
Select Just the push event
, which triggers the Jenkins job whenever there's a push event in the repository.
# 1. Install Jenkins. On Ubuntu, you can use the following command:
sudo apt-get install Jenkins
# 2. Start Jenkins server. Usually, it starts automatically after installation. If not, use the following command:
sudo service Jenkins start
# 3. Open Jenkins on your web browser
http://localhost:8080
We've covered the basics of CI/CD, how to setup Jenkins with GitHub, and how to configure webhooks in GitHub. Your next steps could be to explore more about Jenkins and other CI/CD tools, and understand how to write automated tests for your CI/CD pipelines.
Exercise 1: Setup Jenkins on your local machine and integrate it with a simple Hello World repository on GitHub.
Exercise 2: Create a pipeline in Jenkins that builds your code and runs tests whenever there is a new push event in GitHub.
Exercise 3: Configure email notifications in Jenkins to be alerted whenever a build fails.
Solution 1: Follow the step-by-step guide above.
Solution 2: In Jenkins job configuration, under Build
section, add Execute Shell
and write commands to build and test your code. Under Build Triggers
, select GitHub hook trigger for GITScm polling
.
Solution 3: In Jenkins job configuration, under Post-build Actions
, add E-mail Notification
and enter the recipient email address. Make sure the Jenkins email notification plugin is installed and SMTP server is configured in Manage Jenkins
> Configure System
> E-mail Notification
.