0% found this document useful (0 votes)
80 views154 pages

Jenkins 2025

Jenkins is a robust application for continuous integration and delivery (CI/CD) that automates the building, testing, and deployment of software projects across various platforms. It features automated code integration, deployment, and monitoring, which enhances software quality and reduces risks associated with manual processes. The document provides detailed instructions on using Jenkins, including job creation, configuration, and advanced features like role-based access control and build triggers.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
80 views154 pages

Jenkins 2025

Jenkins is a robust application for continuous integration and delivery (CI/CD) that automates the building, testing, and deployment of software projects across various platforms. It features automated code integration, deployment, and monitoring, which enhances software quality and reduces risks associated with manual processes. The document provides detailed instructions on using Jenkins, including job creation, configuration, and advanced features like role-based access control and build triggers.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 154

1

2
3
4
Jenkins
Jenkins is a powerful application that allows continuous
integration and continuous delivery of projects, regardless of
the platform you are working on. It is a free source that can
handle any kind of build or continuous integration. You can
integrate Jenkins with a number of testing and deployment
technologies. In these notes, we will explain how you can use
Jenkins to build and test your software projects continuously.

Continuous Integration and Continuous Delivery (CI/CD) are


essential practices in modern software development that aim
to streamline and automate the process of building, testing,
and deploying code changes. These practices help
development teams deliver software more efficiently, with
higher quality, and at a faster pace.

Continuous Integration (CI):


CI is the practice of automatically integrating code changes
from multiple developers into a shared repository frequently,
typically multiple times a day. The main goal of CI is to detect
integration issues early in the development cycle, thereby
reducing the chances of conflicts and bugs that arise when
multiple developers work on the same codebase.
Key features of CI:
5
Automatic code integration: Developers frequently merge
their code changes into a central repository, where automated
build and testing processes are triggered.
Automated build and tests: CI systems automatically compile
the code, run unit tests, and perform other validation checks to
ensure the codebase remains stable.

6
Early feedback: By catching issues early, CI allows developers to
fix problems quickly, preventing the accumulation of bugs.

Continuous Delivery (CD):


CD is an extension of CI that focuses on automating the
software release process. It ensures that code changes are
always in a deployable state and ready for production release.
The ultimate goal of CD is to enable frequent and reliable
software releases to end-users with minimal manual
intervention.

Key features of CD
● Automated deployment: The CD pipeline automates the
deployment of code changes to various environments,
including staging and production, with consistent
configurations.
● Release orchestration: CD pipelines manage the entire
release process, coordinating tasks such as database
updates and infrastructure provisioning.
● Rollbacks and monitoring: CD ensures that automated
rollbacks are possible if any issues arise during
deployment. Monitoring is also integrated to track the
application's health post-deployment.

Benefits of CI/CD

7
● Faster time-to-market: CI/CD streamlines the
development and deployment process, reducing the time
it takes to deliver new features and updates to end-
users.
● Higher software quality: Automated testing and
validation catch bugs early, leading to a more stable and
reliable codebase.
● Risk reduction: Frequent integration and automated
deployment enable faster bug identification and recovery,
minimizing risks associated with manual processes.
● Increased collaboration: CI/CD encourages collaboration
among developers, testers, and operations teams,
fostering a culture of continuous improvement.

8
Covering each feature of Jenkins:

1. Timeout- It will be found under the Build Environment


section-> Terminate a build if it’s stuck.
When the system sleeps for some time, e.g. 240 seconds, we
define the
Time-out strategy time e.g. 3 minutes. It means that a job will not
build or fail.

2. Timestamp- It will be found under the Build Environment


Add section-
>
timestamps to the Console Output which means it will notify the time whatever command is
running at what time.

3. Disable/Enable Job- It will be found under the status of a


specific project. You can use this feature to disable or
enable the job build. If you want that nobody can build the
job except you then you can disable the job. And whenever
you want to enable it you can do that too.

9
4. Build a Job concurrently- As you are aware, you couldn’t build a job
concurrently. But if you want to do this, then you have to enable the feature that
will be found under the section of Description named ->Execute concurrent builds
if necessary.

5. Retry count- When your job is not built successfully. So you can retry as many
times as you want, but for that, you have to enable it to define the time and
number of counts.

6. Throttle Builds- When you want that there should be a limited number of
builds asked, then you will use throttle builds. For eg, the Number of builds is 3
and the Time period is minutes. Then there are only 3 builds that will be
successful and possible, not more than that.

10
Creating First Job
1. Click on New Item.

11
2. Enter the job name and choose freestyle project.

3. Follow the below steps.

12
13
4. Click on Build Now

5. As the build is successful. Now click on the green color


text (#1).

14
6. Now, To see the output of your created job. Click on the
Console Output.

7. The Output:

15
Change Jenkins Theme using Plugin
1. Click on Manage Jenkins -> Manage Plugins.

2. Now search the Simple theme plugin, check it and install


without restarting.

16
3. Now that the plugin has been installed, the restart Jenkins
server and log in again.

17
4. Now, go to the Manage Jenkins again and configure the
Plugin by clicking on Configure System.

5. Now, enter the URL of the CSS to change the theme


and apply then, then save it.
URL Link-> Themes Link

18
To change the Jenkins URL
Manage Jenkins -> Configure System.
Enter the desired location or URL.
By Default, URL-> http://localhost:8080/

+Create a new user in Jenkins


1. Go to Manage Plugins -> Manage Users.

19
2. Click on Create user. And enter the further details.

3. New User

20
Jenkins Role-Based Access Control
(RBAC)
1. Install the plugin named Role-based Authorization Strategy
by going into the Manage-Jenkins -> Manage Plugins -
Available and then searching for the plugin name, which is
written above.

2. Now, you have to configure this plugin by going into


Manage Plugin -> Configure Global Security, selecting the
Role-based Strategy, and applying and saving the
configuration.

21
3. Now, the Manage and Assign roles option will appear
under the security section in the Manage Jenkins.

4. Now, go into the section and click on Manage


Roles. Then, create the role named <developer>
which has no access then apply and save.

22
5. Now, when you log in with another user, e.g. Jon Snow.
You’ll get this.

6. Now, go to the Assign Roles and add the user, then give the
developer role to that user. Click on Apply and save.

23
7. If you give access by changing the roles and assigning
the roles to read and build jobs to the other user, It will
look like this.

24
8. If you add one more permission, which is job read, then the
other can see the jobs.

25
GitHub Job without GitHub Plugin

1. Create a Job with freestyle projects.

26
2. Take Source code Management as None (for not github).

27
3. Build Environment -> Check the Delete workspace before build
starts. It
is checked because when you are going to build
The job again it couldn’t succeed with the <git clone>
because the file will already exist. That’s why we
checked that.
Then, write your bash/shell script.

28
4. The Output

29
GitHub Job with GitHub Plugin
1. Create a freestyle project.

2. Source code Management must be GitHub.


And add the further details as written below.

30
The Output

31
How to build a job using Trigger
Builds remotely (Authentication
token)
1. Go to any Job.

32
2. Enter the token name inside the Trigger build
remotely section.

3. Now, cop the URL that was under the token name
field and paste in the new tab

33
4. Now, come to the Jenkins dashboard.
You will see the build has been automatically started.

Build Successful

34
Build Triggers
1. Build a Job through
Incognito Mode and
Terminal

Why?
As I am building a job through just a URL. But when I put the same
URL in incognito mode of any browser, it asked me to log in again to
resolve that issue. Follow the steps below:

1. First of all, I need to install a plugin named Build


Authorization Token Root as
Build Authorization Token Link Official Plugin

35
2. Enter the URL which is written in the tab.

3. The result you can see.

36
The build has been successful.

37
Through Terminal

1. Enter the same URL and make one change before the &
symbol. Use backslash (\).

2. The build has been successful.

38
2. Build after other projects are built
Why?
When you have to build your specific project after some desired
projects. You can use this Build Trigger.

1. Enter the other project that you want to build first.

39
2. Now, run the project that you entered under the Projects to
Watch section.

3. You will see on the left, the project is built.

40
4. If you observe, both build numbers are incremented by 1.

41
3. Build Job Periodically
Why?
When you have to build your job at a specific time or same interval, e.g. every two
minutes. You can use Build periodically under the Build Triggers section.

1. Write the time interval the same as written in the cron job.

42
2. Write the command and apply then save it.

3. Here, you can check it out. The build is automatically done every two
minutes.

43
4. Poll SCM (Source Code
Management)
Why?
This Build trigger is the same as Build Periodically. But there is only one
difference, which is that the project will fetch from the GitHub
repository(mandatory), and if there is no commit in the repository, the job will not
build. But, if there is any commit change in the GitHub repository, then the job
will build as a periodic scheduler, which is also known as a Cronjob/Crontab.

1. Configuration for the Project.

44
45
2. The job is built automatically. But then no job built

3. Changing some file data in the GitHub repository to build a job.

46
4. As the GitHub repository has a new commit. Now, it is building a
job.

5. The Build is successful.

47
The Output

48
How to define variables globally
1. Go to the Manage Jenkins -> Configure System and scroll

down, then look for Global properties.

2. Now, create a job and print the value of the variable by

passing the environment variable.

49
3. Here, you can see the value of the variable appear.

50
Parameterized in Job
1. Define the variable and pass the default value.

51
52
53
Console Output

54
Custom Workspace
1. Create a new job and do the configuration as given below:

55
2. Now, the directory has been created and the file
too. To check it, go to your terminal.

56
Change the display name and project
name
1. Go to the Configuration of the Specific Project-> Enter the

desired name that you want in the text field.

The Output

But the Project hasn’t changed. For that, you have to click on the
Rename button, which is left on the screen, and enter the desired
name.

57
Now, the project name has changed too.

58
Building Upstream and Downstream
Projects
Upstream- Parent job
Downstream- Child
job

That job that is triggering another job is known as the Parent job, and
that job that is triggered by another job/Parent job, is known as the
Child job.

Block build when the upstream project is building


Here, the scenario is that if you are building a parent job, then you
couldn’t build a child job at the same time. To build the child job, you
have to complete the build of the parent job first.

59
60
Block build when downstream project is building

Here, the scenario is that if you are building a child’s job, then you
couldn’t build a parent’s job at the same time. To build the parent job, you
have to complete the build of the child job first.
Complete Reverse of the previous one.

61
62
63
Jenkins Pipeline using Build Pipeline

1. First of all, install the plugin named Build Pipeline.

2. Create two Jobs, the first will be Parent and the


second will be Child job and assign the Post-build
actions in Parent Job for Child job as per below:

64
3. Click on “+” to create the Build Pipeline.

65
4. Choose Type as “Build Pipeline view” and assign the
name of your Pipeline.

5. Now, all you have to do is “Select the Initial Job”


which will be your Parent's job.

66
6. In the last, click on the run button, and the result will
be in front of you like this:

67
Continuous Deployment vs
Continuous Delivery
In Continuous Deployment, whenever the code changes to an
application is released automatically into the production
environment. There is no inclusion of human intervention or
manual clicks.

E.g

1. Create three Jobs, first will be GrandParent, the


second will be Parent job and the third will be Child
job and assign the Post-build actions in GrandParent
Job for Parent job and in Parent Job for Child Job as
per below:

68
69
2. Click on “+” to create the Build Pipeline.

3. Choose “Build Pipeline view” and assign the name of


your Pipeline.

4. Now, all you have to do is “Select the Initial


Job”, which will be your parents’ job.

70
5. The Final Output:

71
Continuous Delivery

In Continuous Delivery, whenever the code changes to an


application are released only by human intervention or through
manual clicks into the production environment.There is no any
Automation in the Continuous Delivery.

E.g,

1. Create three Job, first will be GrandParent, the


second will be Parent job and third will be Child job
and assign the Post-build actions in Grand Parent Job
for Parent job and rest the last will be Manually as
per below:

72
73
2. Click on “+” to create the Build Pipeline.

3. Choose Type “Build Pipeline view” and assign the


name of your Pipeline.

4. Now, all you have to do is “Select the Initial Job”


which will be your Parent job.

74
5. Now, when you run the Pipeline then you will face like
this.

The last job will not run automatically as it is built with


manual intervention.

6. So, to run that build, too. You have to click on


the trigger or run that build(on the right bottom).

75
7. The Final Output:
8.

76
Run Two Job Parallel in Jenkins Pipeline
1. Create three jobs, first will be GrandParent, the
second will be Parent job and the third will be Child
job and assign the Post-build actions in GrandParent
Job for Parent job and in Parent Job for Child Job as
per below:

77
78
6. Click on “+” to create the Build Pipeline.

7. Choose Type “Build Pipeline view” and assign the


name of your Pipeline.

79
8. Now, all you have to do is “Select the Initial Job”
which will be your Parent job.

80
9. The Final Output:

81
Deploy WAR to Tomcat Server
through Jenkins (Automation)

Reference:
● Web Link
● Video Link

1. First of all, Configure the Tomcat Manager by following the


link below:
Tomcat Configuration with Manager

Apache Tomcat 9.0.65 Download Link

<role rolename="admin-gui"/>
<role rolename="manager-script"/>
<role rolename="manager-gui"/>
<user username="aman" password="mypassword" roles="admin-gui,manager-gui,manager-script"/>

The Output should be like this:

82
2. Now, you have to Create Four Jobs:
a. HelloWorld-Test: This Job will perform the testing of
the Project, which is a Spring Boot-based Project.
b. Hello-World-Build: This Job will perform the building of
the Spring Boot Project, which will be a .war file as a
result.
c. HelloWorld-Deploy-Test: In this Job, the deployment
will be performed as a testing deployment to check
whether the Job is successful or not.
d. HelloWorld-Deploy-Prod: This job will perform the
same task that was performed by the last job
(HelloWorld-Deploy-Test), but it will be on the
Production level, where the inclusion is present of
human intervention or manual clicks.

Now, all the jobs have their configuration, which is given below sequentially:

a. HelloWorld-Test

83
84
85
b. Hello-World-Build:

86
87
c. HelloWorld-Deploy-Test

88
89
90
91
d. HelloWorld-Deploy-Prod

92
93
The Output

94
Creating Jenkins Slave
1. First of all, go into Manage Jenkins -> Manage Nodes and
Clouds.

2. To create the new Slave, click on the new node.

95
3. Give the name to your slave and check the radio button of
Permanent Agent, then, click on the Create button.

4. Before going to the subsequent Configurations of your


Jenkins slave,
Follow some steps:
a. Create an EC2 Instance with Inbound rule 22(SSH) at
least.
b. SSH into your instance.
c. Install OpenJDK by the command:
sudo apt install openjdk-8-jre-headless -y
d. Create a directory named jenkins inside the /var
directory.
e. Change the owner of that directory by the given
command:
sudo chown ubuntu:ubuntu jenkins/
f. Now, change the password of your EC2 Instance by the
following commands:
sudo passwd ubuntu sudo
vim sshd_config
sudo systemctl restart jenkins

For more reference, follow the link below:


Change EC2 Instance Password

96
5. Enter the number of executors as per your choice, then enter
the Remote root directory which will be /var/jenkins then, the
launch type must be “Launch agents via SSH” Enter the
Host Name which will be the Public IP of your instance, then
add the credentials of your EC2 Instance (username=
ubuntu and password= aman@123) and
In the last Host, the Key verification Strategy must be
“Non-verifying Verification Strategy”.

97
98
6. Now go to that Slave and click on Relaunch agent.

7. As the Slave is connected.

99
8. You can check on the left side named Linux1.

100
Create Jenkins Pipeline as a Code
1. Create a Job that will be a Pipeline.

2. Write the Declarative Pipeline to run the job of Hello World.

101
3. Now, when you build the job you’ll see look like this:

4. To see the output, hover on the green box and click on


the logs.

102
Multi-Staging Pipeline as a Code

1. Create a Job that will be a Pipeline.

2. Write the Declarative Pipeline.

103
3. The Output:

104
How to run Commands in Pipeline as a Code

105
How to run multiple commands in Pipeline as a code

106
The Output:

107
How to set the Environment variable Globally in
the Code Pipeline

108
How to set the Environment variable Locally in Code
Pipeline

The Output

109
How to take input from the users in the Code
Pipeline

The Output:

110
Pipeline Script of the Last Job

pipeline {
agent
any
paramet
ers {
string(name: 'username', defaultValue: 'Jenkins', description: 'Who is
the Current User') booleanParam(name: 'Graduated?', defaultValue:
'true', description: 'Are you Graduated') choice(name: 'hobby',
choices: ['Cricket','Chess','Football','Hockey'], description: 'Favourite
Sport')
}
stages {
stage('String
Value') {
input {
message "Do we
start?" ok "Yes,
Let's do this"
}
steps {
sh 'echo $username'
}
}
stage('Boolean
Value') { steps
{
sh 'echo $Graduated?'
}
}
111
stage('Choices
Values') {
input {
message "Want to
Continue?" ok
"Yeah! Definitely"
}
steps {
sh 'echo $hobby'
}
}
}
post {
always {
echo 'The Jenkins!!!!'
}
success {
echo 'The Final Acheivement is Here!!!'
}
failure {
echo 'Seriouslly! We got the Failure from the other End!!!!'
}
}
}

112
Introduction
In today’s fast-paced world, automating the provisioning and management of
infrastructure is essential for efficient and reliable deployment of services.
Terraform, a popular infrastructure as code (IaC) tool, combined with Jenkins, a
powerful automation server, provides a robust solution for creating and
managing AWS resources. This blog aims to guide you through the process of
integrating Terraform with Jenkins to automate the creation of services on AWS.
By leveraging the power of these tools, you can achieve consistent and
reproducible infrastructure deployments, reducing manual effort and increasing
operational efficiency.

Objective
The objective of this blog is to demonstrate how to integrate Terraform and
Jenkins to automate the provisioning of AWS resources. We will explore the
step-by-step process of setting up Jenkins, configuring the necessary plugins,
and creating a pipeline that triggers Terraform to create and manage
infrastructure on AWS. By the end of this blog, you will have a clear
understanding of how to leverage Terraform and Jenkins together, enabling you
to automate infrastructure provisioning, deployments, and updates, ultimately
streamlining your AWS service delivery.

Prerequisites
1. Basic understanding of AWS: Familiarity with Amazon Web
Services (AWS) is essential for understanding the concepts and
terminology used throughout this blog. It is recommended to have

113
prior experience working with AWS services like EC2, VPC, IAM,
and S3.
2. Knowledge of Terraform: A foundational understanding of
Terraform is necessary to follow along with the integration process.
Familiarise yourself with the basics of Terraform, including resource
creation, variables, modules, and state management.
3. Understanding of Jenkins: Having prior knowledge of Jenkins and
its core concepts, such as pipelines, stages, and steps, will help you
grasp the integration process more effectively. If you are new to
Jenkins, it is recommended to explore introductory resources or
tutorials to get acquainted with its basic functionalities.
4. AWS Account and Access Key: You will need an active AWS
account with appropriate permissions to create and manage
resources. Additionally, obtain an Access Key and Secret Access
Key with the necessary permissions to interact with your AWS
account programmatically.
5. Jenkins Installation: Set up a Jenkins instance that is accessible
and operational. This could be a local installation or a hosted
Jenkins server. Ensure that you have administrative access to
configure Jenkins and install plugins.
6. Terraform Installation: Install Terraform on the machine or server
where Jenkins is hosted. Follow the official Terraform
documentation to download and set up the appropriate version of
Terraform for your operating system.
7. Jenkins Plugins: Install the necessary Jenkins plugins to integrate
Terraform with your Jenkins environment. Key plugins include
“Terraform Plugin” and “AWS Steps Plugin.” Ensure that these
plugins are installed and properly configured in your Jenkins
instance.
8. Git Repository: Set up a Git repository to host your Terraform
code. This repository will serve as the source for your Jenkins
pipeline, allowing it to retrieve the Terraform configuration and
execute the necessary deployment steps.
By fulfilling these prerequisites, you will be well-prepared to follow the step-by-
step integration guide and successfully automate the creation and management of
AWS services using Terraform and Jenkins.
114
Hands-On
Step:1
Firstly, in order for Jenkins to run the Terraform commands that create the
infrastructure, AWS credentials are required. To achieve this, you need to
download two Jenkins plugins:

1. CloudBees AWS Credentials Plugin: This plugin enables you to


securely store AWS access keys and secret access keys within
Jenkins. It provides a centralised location to manage and configure
AWS credentials that can be used by your Jenkins jobs.

2. AWS Steps Plugin: This plugin integrates AWS functionality


directly into Jenkins pipelines. It offers a set of pipeline steps that
enable you to interact with AWS services, including managing AWS
credentials, executing AWS CLI commands, and working with AWS
resources.

By installing and configuring these two plugins within your Jenkins


environment, you can securely store AWS credentials and leverage the AWS-
specific pipeline steps to interact with your AWS account during the Terraform
deployment process.

115
116
Step 2:
To save your AWS credentials in Jenkins, follow these steps:

• Go to your Jenkins dashboard and navigate to “Manage Jenkins”.


• This time, select “Manage Credentials” from the dropdown menu.
• On the Credentials page, click on “Global credentials (unrestricted)”.
• On the new page, click on the “Add Credentials” link on the left-hand
side.
• Fill in the required fields, including the AWS access key and AWS
secret access key. You can choose an appropriate description for
the credentials to help you identify them later.
• Click on the “OK” button to save the credentials.
• You have now successfully saved your AWS access key and secret
access key in Jenkins. These credentials can be used in your
Jenkins jobs and pipelines to interact with AWS services securely.

117
Step 3:
Now, we have to create the Jenkins Pipeline, which is our main task

118
Step 4:
The following is a basic Pipeline script written using Pipeline Syntax. If you
would like to add additional parameters or explore more advanced
configurations, you can refer to my GitHub repository, where I have provided
examples based on my specific requirements.

119
Step 5:
Now, as I click on Build Now. I’ve created the infrastructure.

120
Some useful links:
Jenkinsfile- https://github.com/AmanPathak-DevOps/Terraform-for-
AWS/blob/master/Non-Modularized/Jenkinsfile

Terraform Code to create Infra- https://github.com/AmanPathak-


DevOps/Terraform-for-AWS/tree/master/Non-Modularized

In conclusion, integrating Terraform with Jenkins allows for streamlined and


automated AWS infrastructure provisioning. By leveraging Terraform’s
declarative configuration and Jenkins’ automation capabilities, you can achieve
consistent and efficient deployments. With this powerful combination, you can
focus on delivering value and adapt to changing business needs effortlessly. Start
your journey toward infrastructure automation today and unlock the benefits of
scalability, reliability, and agility. Happy automating!

121
High Overview

Jenkins Server Setup

1. We have to configure Jenkins. For that, we are going to create an


EC2 server where Jenkins will be installed. Also, we are going to
install some other tools as well, such as Sonarqube and Docker, so
we need more RAM and CPU.
Configurations: t2.large, Ubuntu22.04, Security Group Port Open- 22, 9000,
8080, 8081, and 8082, Storage: 30GB gp2.

122
123
2. After creating an EC2 Instance, log in to the created machine using
SSH.

3. To install Jenkins, you can refer to the GitHub repo, where you just
need to run the script or follow the command to install it on your
machine.
GitHub Repository: https://github.com/AmanPathak-DevOps/Scripts-
Installation.git

124
You can see below that Jenkins has been installed.

4. Now, browse the Jenkins server with the help of public_ip:8080.


Make sure you have opened port number 8080 in the instance’s
security group.

125
5. Get the password using the command
/var/lib/jenkins/secrets/initialAdminPassword.

6. After entering the password, click on Continue.

126
7. Click on “Install suggested plugins”

127
8. For now, you can proceed by clicking on the “skip and continue as
admin”

128
9. The setup is completed.

10. Install the Docker Pipeline plugin


129
SonarQube Server Setup
11. Install the Sonarqube Scanner plugin

12. Install Sonarqube on your EC2 Instance or the local machine.

You can refer to the GitHub repo where you just need to run the script or follow
the command to install it on your machine.

GitHub Repository: https://github.com/AmanPathak-DevOps/Scripts-


Installation.git

apt install unzip


130
adduser sonarqube
wget https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-
9.4.0.54424.zip
unzip *
chmod -R 755 /home/sonarqube/sonarqube-9.4.0.54424
chown -R sonarqube:sonarqube /home/sonarqube/sonarqube-9.4.0.54424
cd sonarqube-9.4.0.54424/bin/linux-x86–64/
./sonar.sh start

13. Set up SonarQube for the EC2/Local server.

Username and password: admin

In the next step, you have to reset your password.

14. Your Sonarqube server is up and running which will look like
this.

131
15. Now, We have to connect the Jenkins Sonarqube scanner
with this Sonarqube server. To do that, click on the profile which is
right of the search box, and go to My Account.

16. To generate the toke for connecting with Jenkins Sonarqube


Scanner with the Sonarqube Server. Click on the Security tab, give
the names to the token, and click on Generate.

132
17. Now, Add the Generated Token in Jenkins. By Dashboard ->
Manage Jenkins -> Credentials -> System -> Global credentials.

Jfrog-Artifactory Server Setup


18. Create a new EC2 Instance t2.medium and install jfrog-
artifactory.

You can refer to the Github Repo in which there is a script called Install-Jfrog-
Artifactory.sh, and run it, which will install Jfrog Artifactory on your machine,
or you can just copy and paste.

GitHub Repository: https://github.com/AmanPathak-DevOps/Scripts-


Installation.git

133
You can also refer youtube video link to integrate Jfrog Artifactory with Jenkins
How to Configure Artifactory in Jenkins

19. Now, set up the Artifactory to upload the artefacts after Code
Analysis is successfully completed.

Click on Get Started.

20. Enter the new password and click Next.

134
21. Click on Skip

22. Click on Skip.

135
23. Create the repo by giving a name to it, make sure the repo
should be generic or Maven, as we have to upload the artefacts for
Java.

24. Name the repo and click on save and finish.

136
25. To integrate Jfrog-Artifactory with Jenkins, we have to
generate token in Jfrog-Artifactory.

Click on Generate Access token.

137
26. Click on Generate.

27. Copy the token.

28. Go to Jenkins and Dashboard-> Manage Jenkins ->


Credentials and paste the token that you have copied from the
138
Jfrog-Artifactory and do the rest as per the below screenshot and
click on Create.

29. Install Docker on the EC2 Server where Jenkins is Installed.


You can refer to the below command, or you can refer to the Github
Repo, where you just need to run the script and install it on your
machine.

GitHub Repository: https://github.com/AmanPathak-DevOps/Scripts-


Installation.git

sudo apt update


sudo apt install docker.io
sudo su -
usermod -aG docker jenkins
usermod -aG docker ubuntu
systemctl restart docker
30. Install minikube on your local machine.

Refer to the given link: https://minikube.sigs.k8s.io/docs/start/

139
You can refer to the Github Repo where you just need to run the script or follow
the command to install it on your machine.

GitHub Repository: https://github.com/AmanPathak-DevOps/Scripts-


Installation.git

sudo apt update


sudo apt upgrade
wget https://storage.googleapis.com/minikube/releases/latest/minikube-linux-
amd64
chmod +x minikube-linux-amd64
sudo mv minikube-linux-amd64 /usr/local/bin/minikube

31. Install ArgoCD by going to


https://operatorhub.io/operator/argocd-operator and clicking on
install. You will get the commands that you have to use to install on
your local machine, where minikube is installed.

32. Command ran, and the argoCD operator has been installed

140
33. Store Docker credentials.

34. Store Github Credentials as well(Personal access token).

141
Deploy on Kubernetes cluster
35. Go to operatorhub.io and enter on argoCD then click the operator
Documentation link

36. Click on usage -> basics and copy the selected script.

142
37. Create a yml file and paste the script into the file.

38. We are using this script to download the argoCD controller.

Now, the last step is to download the argoCD controller which will be done by
the help of the command: kubectl apply -f argocd-basics.yml

39. Here, you can see that the argoCD controller has been created.

40. We need the fourth controller because this is responsible for argoCD UI.

143
41. We want to run this controller on our local machine. So, to do that, I will edit
the fourth controller where I will change Type: ClusterIP to NodePort.

42. We are running the same command to get the services, but this time there is a
difference where we can see the NodePort.

Now, to generate the browser URL, write the command minikube service
argocd-server.

And to get the browser URL, write the command minikube service list, which
you can check in the screenshot below.

144
43. I have clicked on the link, and you will get this UI click on advance and then
click on <your_IP>

44. You can see the ArgoCD UI login Page.

145
45. Here, you have to enter the username and password.

The username will be admin, and to get the password, refer to the screenshots
below.

46. I have got the encrypted password and will copy it.

Now, I have decrypted the password by using the below command


146
47. Now, I have entered the username and password and logged the Argo CD
UI.

48. Click on CREATE APPLICATION. You can see this in the above
screenshot.

Now, to create the application, you have to enter some configurations. You can
check it out in the screenshot below, and in the end, click on CREATE.

147
49. Now, wait for some minutes. argoCD will deploy the application
automatically.

50. Here, I was getting an error because I had written the namespace in the
namespace parameter, which should be the default.

51. So, let’s correct it.

Final Configuration.
148
52. After clicking on Save, click on Refresh, and it will start the process again to
deploy the application.

And my application has deployed successfully, as you can see in the screenshot
below.

53. If you run the command, kubectl get pods. You can see the last two pods that
are running, which ensures that the deployment is successful.

149
54. So, there were some issues that I faced and resolved as well.

Final Output of Every Service and Tool

The Jenkins Pipeline

150
Sonarqube Code Analysis

Uploaded Artefacts to Jfrog Artifactory

151
Deployment using Argo CD Controller on Kubernetes Cluster

152
In conclusion, the above notes provide a beginner-level
introduction to Jenkins and its role in enabling Continuous
Integration and Continuous Delivery (CI/CD) practices. By
understanding the fundamental concepts and features of Jenkins,
beginners can kickstart their journey towards automating their
software development processes and achieving faster, more
reliable project deliveries.

For those seeking to advance their knowledge and skills in


Jenkins, there is a world of possibilities to explore. Jenkins offers
a vast array of plugins and integrations with various tools,
allowing advanced users to tailor their CI/CD pipelines to meet
specific project requirements. By delving deeper into Jenkins'
capabilities, experienced users can optimise their workflows,
integrate advanced testing and deployment strategies, and
harness the full potential of CI/CD for continuous improvement.

Moreover, Jenkins Pipelines offers an exciting avenue for


advanced users to adopt a "pipeline-as-code" approach,
enabling better version control, collaboration, and scalability.
With declarative pipeline scripts, developers can encapsulate
complex build and deployment logic, making it easier to manage
and maintain their CI/CD workflows effectively.

While the notes provide a solid foundation for beginners, it is


essential to continue exploring Jenkins and other related
technologies to stay up-to-date with the latest advancements in
153
CI/CD practices. Online tutorials, documentation, forums, and
community resources are valuable sources to deepen one's
expertise and stay ahead in the rapidly evolving landscape of
DevOps and CI/CD.

Whether at the beginner or advanced level, embracing Jenkins


as a pivotal tool in the software development lifecycle empowers
teams to automate, collaborate, and deliver high-quality software
efficiently. By leveraging Jenkins' capabilities and staying
curious, developers can continually refine their CI/CD processes
and drive innovation in the dynamic world of modern software
development.

154

You might also like