CI/CD And Jenkins

CI/CD And Jenkins

Hello readers this document that you are going through now is focused on Jenkins so let's start with it

introduction

we are going to learn about ci/cd so first we must know what is that in simple language.

CI is continuous integration.

CD is continuous delivery or continuous deployment.

CI/CD is a technique that is commonly used in organizations and significantly decreases SDLC.

There must be multiple functionalities that may be developed for a product every day, these newly developed functionalities are continuously integrated into the product and continuously delivered or deployed to the user of the production using the process of CI/CD.

There are multiple tools for performing ci/cd but we will discuss about Jenkins

Jenkins - a brief intro

  1. In common terms, Jenkins is ci/cd tool

  2. In technical terms, we can define Jenkins as an orchestrator that integrates various tools and helps automate various steps in CI/CD.

  3. it can be also used to set up the software in different environments such as dev, stage and production.

  4. Jenkins works on Java 8 or Java 11 therefore to use Jenkins you must have Java installed on your system.

why do we need ci/cd tool

If we develop a product for our customer it includes a series of steps before it reaches the customer for use.

these steps may include unit testing, static code analysis, code quality test, reports, deployment or many other steps.

if we perform each step manually every time then it will take months for that change to reach to customer.

here ci/cd tool comes into the picture which automates most of our tasks.

A developer will develop functionality and then review it further improve it and develop a newer version of it until he is satisfied, once he is satisfied he pushes the changes to the Version control system like GitHub after that ci/cd comes into the picture and takes care of multiple types of testing and build and at last deploy it to the user system.

Jenkins uses

Jenkins is a good ci/d tool.

apart from being a good ci/cd tool, Jenkins can also set up the software in different environments.

  1. Dev environment:- Jenkins first set up the software in the dev environment where the QA tester and other developers will test it. this environment has less CPU and RAM.

  2. Stage: - If it works fine in the dev environment it is set up in the stage environment where it is tested with more CPU and RAM.

  3. production:- this is the environment where the software is used with full functionality it is the environment in which the customer uses the product.

we can also use Jenkins for role-based access control like we can create users and assign them roles we need to install a plugin called the role strategy plugin.

Jenkins jobs

jenkins jobs are the things or steps that are to be performed for the successful deployment or delivery of the software.

we can create a job using Jenkins ui

we can trigger builds using the build option provided in Jenkins ui or we can trigger build remotely using links

we can chain job execution in Jenkins that is we can create multiple jobs and align the builds such that once the first job is build then the next job is to build and so on.

we can integrate git with jenkins also.

we can monitor jobs using catlight which is plugins in jenkins

problems with jenkins

  1. it does waste of resources, because we have to install Jenkins instance on each node for each developer even if they are not making changes there must be Jenkins installed which consumes RAM and CPU or generally compute resources.

  2. It can not properly scale up and scale down according to need.

a solution to these problems is to use other ci/cd solutions like GitHub actions and gitlab ci.

Internal Architecture of Jenkins

  1. Jenkins follows master slave architecture where there is a single master and multiple slaves. there is one master node installed on the main system and it creates multiple slave Jenkins node on the different system

  2. this architecture help in creating different types of users each with different roles and each with limited access to the project.

  3. master is used only for scheduling purposes.

Since a single Jenkins instance can not handle all load it creates multiple worker nodes and it acts as master and assigns roles to the workers.

if all the load is to be handled by a single instance (only the master node) it may face multiple problems including conflicting packages for ex let us suppose one team wants Python 2 and another wants Python 3 it will be conflicting to install both on the same instance so multiple slaves will be created each with their own required version of python.

using docker as an agent in Jenkins

using docker as an agent solves the problem regarding the wastage of resources because containers are easy to create and destroy.

containers are lightweight and can be easily modified using dockerfile.

containers are created only when needed if the container after the job is executed container is destroyed.

JenkinsFile

Jenkins file allows us to combine the steps including build, test, and deliver to the application itself.

it's just a text file stored at the same place in the git repository where the source code is present.

All the project's source code has its own Jenkins file.

Jenkins file is a way to write a declarative pipeline it is written in Groovy script, here we specify what steps are to be performed during the SDLC using code written in Groovy.

this is the basic information about Jenkins which only centered on placement preparation there is much more to learn about Jenkins.