Jenkins? đ | GitHub Actionsđ¤
Huh! what is CICD first ?
In this article i will talk about my learning experience of Jenkins as well as GitHub actions, as a beginner these are the major softwareâs that are used for CICD
Nowadays companies have a clear goal of delivering applications quickly and reliably, itâs crucial for any company to survive. his is where CI/CDâContinuous Integration and Continuous Delivery/Deploymentâsteps in. Itâs a method that automates the journey of code from development to production.
What is CICD?
Think of CI/CD as a way to ensure that your application moves through various stagesâcoding, testing, deploymentâefficiently and without manual involvement.
As the word itself suggests, it has 2 things:
Continuous Integration (CI): Devs regularly merge their code into a shared repository, and automated tests run on that repository to ensure that the code integrates smoothly.
Continuous Delivery/Deployment (CD): After the testing is done, the code is set for delivery or deployed straight to production.
Usually, the tests are gonna take a lot of time, and a person is assigned to each of the task, like one for unit testing, one for end to end testing, and one for reports generation, and etc etc.
CICD approach avoids long, manual processes of testing and deploying software, saving time and reducing the chances of errors.
Jenkins into CICD
Jenkins is a very popular open source tool that manages and automates the CICD process. It monitors your code repository for changes and, when new code is committed, it triggers the necessary steps: testing, building, and deploying.
How Jenkins Works:
Monitoring: Jenkins keeps an eye on your version control system (GitHub).
Testing: Once a change is detected, Jenkins runs automated tests (unit, integration, etc.).
Deployment: After the tests pass, Jenkins can automatically deploy the code to your development, staging, or production environments.
Itâs shown here,
Setting Up Jenkins
(I Have done this on an EC2 instance, you can do it anywhere in your PC)
pre-requisite : Java JDK
Install Java JDK: Jenkins requires Java to run. ( as itâs built on java )
Jenkins on AWS EC2: I set up an Amazon EC2 instance to host Jenkins and configured security settings to allow web access.( Inbound and outbound Rules )
Configure Jenkins: I accessed Jenkins via the web interface, created an admin user, and installed the recommended plugins to enable full CI/CD functionality.
In Jenkins, the traditional setup relies on a master-worker architecture (The one we made above is the master). Hereâs how it works:
Master Node: The brain of Jenkins, which schedules the jobs, monitors the nodes, and keeps track of jobsâ execution status.
Worker Nodes: These are machines (physical or virtual) that actually execute the jobs assigned by the master. They run the tests, build the code, and handle deployments.
While this system works well, it has some challenges, particularly when scaling:
Resource Consumption: Worker nodes often require dedicated physical or virtual machines, which can become costly as your CI/CD needs grow.
Scaling Limits: Managing multiple worker nodes means you need to manually add machines when more resources are needed, leading to inefficient scaling.
Maintenance: Each worker node needs to be maintained, configured, and monitored, adding to the overhead.
Docker-Containers Came Into Picture
A more modern, efficient approach is using Docker Agents. Docker coz:
Lightweight and Flexible: Instead of dedicating full machines as worker nodes, Docker containers act as agents. Containers are lightweight, start quickly, and can be destroyed after the job is done.
Cost-Efficient Scaling: With Docker agents, scaling is simpler. Jenkins can dynamically launch new Docker containers as needed to handle jobs, and then stop them once theyâre done. You donât need to worry about leaving idle machines running.
Isolated Environments: Docker provides isolated environments for each build. This ensures that different jobs donât interfere with one another, which is particularly useful when multiple builds with different dependencies are running.
Consistency: Every Docker container can be based on the same image, meaning all builds have the same environment, ensuring consistency. You don't have to worry about different versions of tools across worker nodes.
Setting Up Docker Agents in Jenkins
Hereâs a simplified breakdown of how I set up Docker agents in Jenkins:
Install Docker: First, I installed Docker on the Jenkins master machine (an AWS EC2 instance in my case).
Grant Docker Access: I configured Jenkins to have the necessary permissions to manage Docker. This involved adding the Jenkins user to the Docker group and restarting the Docker service.
Install Docker Pipeline Plugin: In Jenkins, I installed the Docker Pipeline Plugin, which allows Jenkins to interact with Docker containers within its pipelines.
Create a Docker Pipeline: With the plugin installed, I could configure my Jenkins pipelines to run builds inside Docker containers.
pipeline {
agent {
docker {
image 'node:14-alpine' // This specifies the Docker image for the agent
}
}
stages {
stage('Build') {
steps {
echo 'Building inside Docker container...'
}
}
stage('Test') {
steps {
echo 'Running tests inside Docker container...'
}
}
stage('Deploy') {
steps {
echo 'Deploying from Docker container...'
}
}
}
}
Why This Approach is Better for Scaling
With Docker agents, Jenkins can scale in a horizontal manner by simply launching additional containers whenever more resources are needed, instead of having to manage and maintain additional worker nodes. When more jobs are queued, Jenkins can automatically create new Docker agents and then clean them up after use, which provides better resource utilization and cost savings.
In short, Docker agents allow Jenkins to be:
More scalable: Easily scale by spinning up and tearing down Docker containers on demand.
More cost-effective: No need to maintain idle worker nodesâDocker containers are used only when needed.
Consistent and isolated: Each container provides a consistent environment, which is isolated from other jobs, reducing potential conflicts.
Continue reading on GitHub actions here!
https://bharadwajreddy1406.hashnode.dev/learning-github-actions
Conclusion
In the development lifecycle, Jenkins acts as an orchestrator, managing everything from code integration to deployment across various environments, ensuring that the process is automated, efficient, and consistent.
Thank You for reading! đâď¸
Subscribe to my newsletter
Read articles from Bharadwaj Reddy directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Bharadwaj Reddy
Bharadwaj Reddy
Hey there! Iâm Bharadwaj Reddy, currently an undergrad at Keshav Memorial Institute of Technology. Iâm a full stack developer who loves building cool web applications with React, Node.js, and MongoDB. On top of that, I also love exploring machine learning with TensorFlow and PyTorch. Iâm pretty comfortable navigating GitHub for version control and love tinkering with AWS for deploying projects. I post my regular learnings on Devops and other studies