DevOps- Jenkins

Jenkins:

→ Jenkins is a open-source automation tool/server/software, used for continuous Integration(CI) and continuous Deliver/Deployment(CD) pipelines.

→Jenkin was developed by Kohsuke in 2004 using java language.

→Originally it is renamed as Hudsen, in 2011 it is again renamed as Jenkins

Uses of Jenkins:

→ Jenkins is used for automating various tasks related building, testing, deploying application/ software.

→ Acts as a central system for automating the task through out SDLC.

→ It is primarly used to implement CI, CD pipelines, it will automate process of integrating the code changes, executing test cases, checking the quality of source code and deploying the application to various environment.

→ Jenkins is highly extensible, it has strong community and so many plugins that will allow to integrate with any tool or technology used in modern/latest software development.

Continuous Integration (CI):

→ Alternative CI Tools for Jenkins is → GIT Actions, GIT Lab CI, Circle CI, Travis CI, Azure CI, Bamboo.

→ Continous Integration is a process of automating the changes, build and test of code everytime there is a changes to source code.

→ It is a devops practice where developers integrate their code into a shared remote frequently several times in a day.

→ Each integration(change) is verified by an automated build to detect integration errors as quickly as possible.

Continuous Delivery:

→ It’s a devops practice of automatically preparing code changes for release to production. It will allow us to deploy the code into lower environment( Dev environment, QA envir, stagging).

CD Tools→ Jenkins, spinnaker, urbon code deploy, argo Cd, GIT actions, Azure Cd.

Continous Deployment:

→ It will allow us to deploy the code into production environment, without manually testing the souce code.

→ Jenkins has almost 1900+ plugins, this plugins help jenkins to communicate with various applications.

→ It is easy to install, has simple configurations through web interface

Challenges or Drawback of Jenkins:

→ Jenkins will consume more resources( CPU, Memory).

→ Difficult to maintain Plugins

Jenkins Installation:

→ Jenkins.io → Official website

→ Atleast 2 GB memory

→ version 2.479.1

→ Java 21/ java 17

→ port : 8080

→ create a Jenkins server with → t2.medium, port 8080, 10gb configure storage

→ SSH to the server

→ check for the java version-21, if not install the java by using the below commands

sudo rpm --import https://packages.adoptium.net/artifactory/api/gpg/key/public

sudo tee /etc/yum.repos.d/temurin.repo

<<EOF [Temurin]

name=Temurin OpenJDK

baseurl=https://packages.adoptium.net/artifactory/rpm/amazonlinux/2/x86_64

enabled=1

gpgcheck=1

gpgkey=https://packages.adoptium.net/artifactory/api/gpg/key/public

EOF

sudo yum update -y

sudo yum install -y temurin-21-jdk

java -version

→ Now install the Jekins

sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo

sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key

sudo yum install -y jenkins

sudo systemctl enable jenkins

sudo systemctl start jenkins

→ Jenkins is in the path of var/lib/

→ Now login to the jenkins

<ip>:8080 (port)

→ We can see the login page there we have to copy the password in order to login

follow the path mentioned in the login page and get the password

→ Click on Install suggested plugins

→ Fill the required details and save.

Creating a Job:

Job - A piece of code that performs certain task when it is executed.

→ Login to the jenkins, go to dashboard, click on create a job.

- > Now configure the job,

→ Install git in the jenkins server

→ Click on build now to run the job

→ Click on invoke top-level Maven targets

→ Then add clean package command in it, but before adding the build steps we need to install maven as maven is there in the server in order to add the build steps.

adding the maven to the jenkins

\>Click on manage Jenkins

→Click on Tools

→ Add Maven

→ Now select the added Maven and its version in the build step

now we have added maven to the jenkins we can build the source code now

→ Click on Build now to run the updated,

The source code is now deployed into jar file

→ The code Builded, now we need to test the code quality by using sonarqube

add the sonar:sonar to the build step goals

→ Click on build now to run the updated job

→ Now we have to deploy the artifact into a repository, Nexus

→ Open nexus, create a maven release and snapshot repository and add those url in the pom.xml

→ open Maven, in there add nexus user and password details in the settings.xml file

→Set the new goals in the build step

→ Now run the job, by clicking the build now

→ The artifact is moved to the nexus repository

→ Till now we have added the source code in the git hub, and builded the Source code into .jar file using maven, and tested the code quality using sonarqube and added the builded artifact to the Nexus repository.

→ Now we have to deploy the artifact into the remote repository by using Tomcat

→ open Jenkins, click manage jenkins, select pulgins, we can see the already installed and available plugin in there.Click on available plugins , search for deploy to container select it and install

→ Now go to your job in the configure, below build steps we can see the post-build Actions, in that select the deploy war/jar to a container option.

add credentials

here the username and password are the tomcat user and password

→Now add the manger script access in the tomcat-users.xml file

→ Now run the job with the latest updates

0
Subscribe to my newsletter

Read articles from Sandhya Kalikiri directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Sandhya Kalikiri
Sandhya Kalikiri