Jenkins CICD with GitHub Integration…
5 min readApr 14, 2023
What is Jenkins???
- Jenkins is a tool that is used for automation.
- Its an open-source server that allows all the developers to build, test and deploy software.
- It works or runs on java as it is written in java.
- By using Jenkins we can make a continuous integration and continuous delivery/deployment of projects or end-to-endpoint automation.
What is GitHub???
- GitHub is a code hosting platform for collaboration and version control.
- GitHub lets us work together on projects.
- A GitHub repository can be used to store a development project.
- It can contain folders and any type of files (HTML, CSS, JavaScript, Documents, Data, Images).
Step1: Launch an AWS Instance-
- Launch a new instance with any name(ex- Jenkins_project).
- Select Ubuntu under AMI and t2.micro in Instance Type.
- Create new key pair and attached under key pair name.
- Tick Allow HTTPS, HTTP traffic from internet.
- Hit Launch Instance.
NOW OUR INSTANCE IS READY TO WORK :))
Step2: Install Jenkins and docker in it-
- Create a script having below code and run that script to download jenkins and docker.
- vim install.sh
curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key | sudo tee \
/usr/share/keyrings/jenkins-keyring.asc > /dev/null
echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \
https://pkg.jenkins.io/debian-stable binary/ | sudo tee \
/etc/apt/sources.list.d/jenkins.list > /dev/null
sudo apt-get update
sudo apt-get install jenkins -y #This will install jenkins in our machine.
sudo apt-get install docker.io #This will install docker in our machine
sudo usermod -aG docker $USER #This will provide docker privilege to running user by adding user into docker group.
sudo usermod -aG docker jenkins #This will provide docker privilege to jenkins by adding user into docker group.
sudo reboot #Reboot our machine.
#After all steps are executed, reconnect your instance.
- chmod +x install.sh
- bash ./install.sh
Step3: Configure Jenkins-
- Enter your instance public ip on browser and you will get below interface.
- Open Instance and run-> vim “path_of_initialAdminPassoword” and you will get password.
- Paste the password and Install suggested plugins.
Step4: Create first job on Jenkins-
- From the Jenkins interface home, select New Item and enter any name and select Freestyle Project and hit Ok.
- Under Source Code Management Section, click git and add your repo url.
- Now, run ssh-keygen in your instance so that it will generate public private key to create connection between github and jenkins.
- go inside the directory where key is stored, cd .ssh
- Now, we have to give our public key to github and private key to jenkins.
- Run, cat id_rsa.pub and paste that key into github.
Login into GitHub -> Open setting -> Under Access Section Click on SSH and GPG keys -> Add SSH Key
- Run cat id_rsa and paste that key into jenkins credentials.
- Under Source code Management, add credentials -> Jenkins -> Under kind select SSH with private key, inside private key tick enter directly and enter your private key -> Hit Add.
- Under Build Triggers Section, tick GitHub hook trigger for GITScm polling.
- Now, Add build step under execute shell.
docker build . -t node-jatin-app #This will build image from dockerfile with name node-jatin-app
docker run -d --name node-ctr1 -p 8000:8000 node-jatin-app #This will run container with name node-ctr1 ,-p = mapping container port with application port, -d = daemon mode i.e in background
- Click on apply and Save.
- Now, add “git integration plugin” in jenkins.
Manage jenkins → manage plugins -> Available Plugins -> search github integration.
- Add Webhook to integrate github, Open Repo setting -> Webhook -> Add Webhook -> enter jenkins url(http://”PublicIP”:8080/github-webhook) inside payload url , select application/json under content type -> Click on Add Webhook.
**Tick indicates our jenkins is connected to github**
- Change anything in code, our deployment will starts automatically.
- You can also check your code is saved under below path.
/var/lib/jenkins/workspace/todo-cicd
Congrats!!Our deployment is completed successfully with the help of integration b/w jenkins and github.
For more projects please follow me!!!