Jenkins? 👀 | GitHub Actions🤔

Bharadwaj ReddyBharadwaj Reddy
5 min read

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:

  1. Monitoring: Jenkins keeps an eye on your version control system (GitHub).

  2. Testing: Once a change is detected, Jenkins runs automated tests (unit, integration, etc.).

  3. Deployment: After the tests pass, Jenkins can automatically deploy the code to your development, staging, or production environments.

It’s shown here,

💡
[Developer Commits Code] --> [Jenkins Detects Change] --> [Run Tests] --> [Deploy Code]

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:

  1. Resource Consumption: Worker nodes often require dedicated physical or virtual machines, which can become costly as your CI/CD needs grow.

  2. Scaling Limits: Managing multiple worker nodes means you need to manually add machines when more resources are needed, leading to inefficient scaling.

  3. 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:

  1. 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.

  2. 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.

  3. 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.

  4. 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:

  1. Install Docker: First, I installed Docker on the Jenkins master machine (an AWS EC2 instance in my case).

  2. 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.

  3. Install Docker Pipeline Plugin: In Jenkins, I installed the Docker Pipeline Plugin, which allows Jenkins to interact with Docker containers within its pipelines.

  4. 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! 😎✌️

0
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