Jenkins 2025
Jenkins 2025
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.
6
Early feedback: By catching issues early, CI allows developers to
fix problems quickly, preventing the accumulation of bugs.
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:
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.
12
13
4. Click on Build Now
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.
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.
18
To change the Jenkins URL
Manage Jenkins -> Configure System.
Enter the desired location or URL.
By Default, URL-> http://localhost:8080/
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.
21
3. Now, the Manage and Assign roles option will appear
under the security section in the Manage Jenkins.
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
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.
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:
35
2. Enter the URL which is written in the tab.
36
The build has been successful.
37
Through Terminal
1. Enter the same URL and make one change before the &
symbol. Use backslash (\).
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.
39
2. Now, run the project that you entered under the Projects to
Watch section.
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.
44
45
2. The job is built automatically. But then no job built
46
4. As the GitHub repository has a new commit. Now, it is building a
job.
47
The Output
48
How to define variables globally
1. Go to the Manage Jenkins -> Configure System and scroll
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
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.
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
64
3. Click on “+” to create the Build Pipeline.
65
4. Choose Type as “Build Pipeline view” and assign the
name of your Pipeline.
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
68
69
2. Click on “+” to create the Build Pipeline.
70
5. The Final Output:
71
Continuous Delivery
E.g,
72
73
2. Click on “+” to create the Build Pipeline.
74
5. Now, when you run the Pipeline then you will face like
this.
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.
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
<role rolename="admin-gui"/>
<role rolename="manager-script"/>
<role rolename="manager-gui"/>
<user username="aman" password="mypassword" roles="admin-gui,manager-gui,manager-script"/>
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.
95
3. Give the name to your slave and check the radio button of
Permanent Agent, then, click on the Create button.
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.
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.
101
3. Now, when you build the job you’ll see look like this:
102
Multi-Staging Pipeline as a Code
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:
115
116
Step 2:
To save your AWS credentials in Jenkins, follow these steps:
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
121
High Overview
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.
125
5. Get the password using the command
/var/lib/jenkins/secrets/initialAdminPassword.
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.
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.
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.
132
17. Now, Add the Generated Token in Jenkins. By Dashboard ->
Manage Jenkins -> Credentials -> System -> Global credentials.
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.
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.
134
21. 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.
136
25. To integrate Jfrog-Artifactory with Jenkins, we have to
generate token in Jfrog-Artifactory.
137
26. Click on Generate.
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.
32. Command ran, and the argoCD operator has been installed
140
33. Store Docker credentials.
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.
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>
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.
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.
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.
150
Sonarqube Code Analysis
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.
154