0% found this document useful (0 votes)
11 views

CND - Jenkins - Introduction - Unit-III-II

Uploaded by

Dhanush reddy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

CND - Jenkins - Introduction - Unit-III-II

Uploaded by

Dhanush reddy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 29

Junkins

Introduction

Dr. Gagan Kumar Koduru


Associate Professor
MLRIT
Course Contents
1. Definition of Jenkins
2. Install & Configure Jenkins
3. Jenkins Architecture Overview
4. Creating a Jenkins Job
5. Configuring a Jenkins job
6. Introduction to Plugins
7. Commonly used plugins (Git Plugin,)
8. Jenkins Build Pipe Line
Definition of Jenkins
 Jenkins is an open-source automation server that helps automate software
development tasks like building, testing, and deploying.
 It's a Java-based program that can run on many operating systems, including Windows,
Linux, and macOS.
 Jenkins can be installed using native system packages, Docker, or by running it
standalone on a machine with a Java Runtime Environment (JRE).
 Jenkins can be used for continuous integration (CI) and continuous delivery (CD). It
can …
• Automate testing and reporting on changes to a codebase
• Integrate different branches of code into a main branch
• Detect defects in a codebase
• Build software
• Prepare code for deployment
• Deploy code to containers, virtual machines, and cloud servers
Definition of Jenkins
Features of Jenkins:
•Easy installation: Jenkins is based on Java, an enterprise development language, and is
easy to install, set up, and use on any platform.
•Easy configuration: Jenkins can be set up and configured through its web interface
•Plugins: Jenkins supports third-party plugins, which contribute to its flexibility and scripting
language. For example, the Maven plugin integrates Jenkins with Apache Maven, a build tool
for Java projects
•Pipeline as code: A new setup experience in Jenkins 2 that allows users to modify pipeline
code without special editing permissions
•Documentation and community: Jenkins has a large knowledge base, documentation, and
community resources
•Multi-cloud environments: Jenkins supports hybrid and multi-cloud environments
•Distributed builds: Jenkins supports distributed builds using a master-slave architecture,
which reduces the load on the CI server
Jenkins is integrating various DevOps
stages:
Install & Configure Jenkins
To install and configure Jenkins on a Windows machine, follow these steps:
1.Prerequisites
• Java Installation: Jenkins requires Java to run. You need to install the Java
Development Kit (JDK) or Java Runtime Environment (JRE) on your system.
2. Download and Install Jenkins
• Visit the Jenkins website and download the Windows installer (.msi file).
• Run the downloaded installer and follow the installation steps:
a. Choose the installation folder (default is C:\Program Files (x86)\Jenkins).
b. Jenkins will automatically install as a Windows service.

3. Start Jenkins Service


After installation, Jenkins runs as a Windows service. To start Jenkins:
• Open the Windows Services Manager by typing services.msc in the Run dialog
(Win+R). Locate Jenkins in the list, right-click it, and click Start.
• You can also start Jenkins from the Command Prompt:
• Type ‘net start Jenkins’ and enter
Install & Configure Jenkins
4. Access Jenkins Web Interface
Jenkins by default runs on port 8080. You can access it from your browser using:
http://localhost:8080

5. Unlock Jenkins
Administrator password while accessing Jenkins for the first time. To retrieve the password:
1.Navigate to the C:\Program Files (x86)\Jenkins\secrets folder.
2.Open the initialAdminPassword file with a text editor and copy the password.
3.Paste the password into the Jenkins web interface.
6. Install Plugins
After unlocking Jenkins, you will be prompted to install plugins. Jenkins offers two options:
•Install suggested plugins: Recommended for new users.
•Select plugins to install: Customize the plugins based on your needs.

You can add or remove plugins later via Manage Jenkins > Manage Plugins.
7. Create Admin User
• Once plugins are installed, Jenkins will ask you to set up your admin user:
• Enter a username, password, and other details. Save the settings
Install & Configure Jenkins
8. Configure Jenkins
Step 1: Set Java Path (Optional but Recommended)
Ensure that Jenkins uses the correct Java version:
1. Go to Manage Jenkins > Global Tool Configuration.
2. In the JDK section, add a new JDK installation and provide the path to your Java
installation.
Step 2: Configure Jenkins Home Directory (Optional)
By default, Jenkins stores its data in C:\Program Files (x86)\Jenkins.
You can change the home directory if needed by editing the Jenkins.xml configuration file
in the Jenkins installation folder.
1. Open C:\Program Files (x86)\Jenkins\Jenkins.xml in a text editor.
2. Locate the following section:
<env name="JENKINS_HOME" value="%BASE%/Jenkins"/>
3. Change the value to the desired directory and restart the Jenkins service.

9. Install Additional Plugins


To extend Jenkins functionality (e.g., to integrate with Git, Maven, Docker, etc.), you can
install additional plugins:
1.Go to Manage Jenkins > Manage Plugins.
2.Under the Available tab, search for and install the plugins you need.
Install & Configure Jenkins
10. Setup Jenkins Jobs
Now that Jenkins is configured, you can start creating jobs to automate your builds:
•Click New Item in the Jenkins dashboard.
•Choose the type of job (Freestyle, Pipeline, etc.).
•Configure source control (e.g., Git) and build triggers (e.g., Poll SCM or Build periodically).
•Add build steps such as executing shell commands, running Maven builds, etc.
11. Backup Jenkins (Optional but Recommended)
To back up Jenkins configuration and jobs, you need to regularly back up the JENKINS_HOME
directory (default is C:\Program Files (x86)\Jenkins or any custom path).
You can also install plugins like ThinBackup to automate backups.
12. Secure Jenkins (Optional but Recommended)
Enable HTTPS (Optional): To secure Jenkins over HTTPS, use an SSL certificate. You can
use IIS as a reverse proxy or configure the Jenkins service to directly handle HTTPS using an
SSL certificate.
Manage User Permissions: Go to Manage Jenkins > Configure Global Security to set up
user roles and restrict anonymous access.
13. Start Jenkins on Boot
Jenkins is installed as a Windows service by default, which means it starts automatically on
boot. You can verify this in the Services window (services.msc).
Jenkins Architecture Overview
Jenkins follows Master-Slave architecture to manage distributed builds. In this
architecture, slave and master communicate through TCP/IP protocol.
Jenkins architecture has two components:
•Jenkins Master/Server
•Jenkins Slave/Node/Build Server
Jenkins Architecture Overview
Jenkins Master
•The main server of Jenkins is the Jenkins Master. It is a web dashboard which is
nothing but powered from a WAR file.
•By default it runs on 8080 port.
•With the help of Dashboard, we can configure the jobs/projects but the build takes
place in Nodes/Slave.
•By default one node (slave) is configured and running in Jenkins server.
•We can add more nodes using IP address, user name and password using the
ssh, jnlp or webstart methods.

The server's job or master's job is to handle:


•Scheduling build jobs.
•Dispatching builds to the nodes/slaves for the actual execution.
•Monitor the nodes/slaves (possibly taking them online and offline as required).
•Recording and presenting the build results.
•A Master/Server instance of Jenkins can also execute build jobs directly.
Jenkins Architecture Overview
Jenkins Slave
Jenkins slave is used to execute the build jobs dispatched by the master. We can
configure a project to always run on a particular slave machine, or particular type of
slave machine, or simple let the Jenkins to pick the next available slave/node.

As we know Jenkins is developed using Java is platform independent thus Jenkins


Master/Servers and Slave/nodes can be configured in any servers including Linux,
Windows, and Mac.
Creating a Jenkins Job
Step 1 − Go to the Jenkins dashboard and Click on New Item
Creating a Jenkins Job
Step 2 − In the next screen, enter the Item name, Eg. Helloworld. Choose the ‘Freestyle
project option’

Step 3 − The following screen will come up in which you can specify the details of the job.
Creating a Jenkins Job
Creating a Jenkins Job
Step 4 − We need to specify the location of files which need to be built. In this
example, we will assume that a local Git repository (E:\Program) has been setup
which contains a ‘HelloWorld.java’ file. Hence scroll down and click on the Git
option and enter the URL of the local Git repository.
Note − If the repository hosted on GitHub, you can also enter the URL of that
repository here. In addition to this, you would need to click on the Add button for
the credentials to add a user name and password to the GitHub repository so that
the code can be picked up from the remote repository.

Step 5 − Now go to the Build section and click on Add build step → Execute
Windows batch command

Step 6 − In the command window, enter the following commands and then click
on the Save button.

Javac HelloWorld.java
Java HelloWorld
Creating a Jenkins Job
Creating a Jenkins Job
Step 7 − Once saved, you can click on the ‘Build Now’ option to see if you have
successfully defined the job.

Step 8 − Once the build is scheduled, it will run. The Build history section shows
that a build is in progress.

Step 9 − Once the build is completed, a status of the build will show if the build was
successful or not. In our case, the following build has been executed successfully.
Click on the #1 in the Build history to bring up the details of the build.

Step 10 − Click on the ‘Console Output’ link to see the details of the build

Apart from the steps shown above there are just so many ways to create a build
job, the options available are many, which what makes Jenkins such a fantastic
continuous deployment tool.
Creating a Jenkins Job
Creating a Jenkins Job
Creating a Jenkins Job
Introduction to Plugins
 Plugins are small, independent programs that can improve and extend the functionality of
Jenkins CI/CD.
 There are over 1,900+ Jenkins plugins available right now and it keeps on increasing
month by month. So there is a plugin to suit almost every need in software development.
 We can Install the Jenkins Plugins from the Jenkins Update Centre. It is a centralized
repository of Jenkins plugins which is being maintained by the Jenkins community.

Benefits of Using Jenkin Plugins


• Helps to Automate Task: Jenkins Plugins are very useful to automate tasks to reduce
manual efforts in the software development process.
• Simplifies Testing: Jenkins Plugins can improve the quality of software by automating
testing and analysis.
• Reduces Human Error: Automating any task using the Plugins can reduce Human errors.
• Increased Agility: Jenkins Plugins will increase the agility of software development teams
by making it easier to release new software changes and resolve bugs more frequently.
Introduction to Plugins
Popular Jenkin Plugins
There are over 1900+ Jenkins Plugins available. So to keep it simple to understand we are listing only
the top 10 most popular Jenkins Plugins.
S: No Jenkins Plugin Use or Purpose
Used to transfer GitHub repository data and helps to schedule your project builds
1 Git Plugin and automatically triggers after commit changes.
Used to run the dynamic agents in a Kubernetes cluster and to manage
2 Kubernetes Plugin Kubernetes Pods for each agent on the Docker image.
Helps to manage Docker containers and services -creating, building, pushing,
3 Docker Plugin running, and managing images.
Helps to integrates Jenkins with Atlassian Jira Software to automatically transfer
4 Jira Plugin the development and build-related data.
Helps to analyse code quality by identifying vulnerabilities, bugs and duplication
5 SonarQuobe Plugin of codes while running Jenkins jobs.
Maven Integration
6 Supports Spring boot applications and Apache Maven projects.
Plugin
Amazon EC2 Used for various EC2 operations and management to support directly from
7
Plugin Jenkins servers.
8 Pipeline Plugin Used for managing Jenkins CI/CD Pipelines.
9 Metrics Plugin Used to measure the performance metrics of software applications.
Helps in analysing the phases of software development and better exception
10 Blue Ocean Plugin handling. This plugin comes with built-in features branching and pulling requests
which helps in team collaboration and faster release update for the software.
How to Install Jenkins Plugins?
Step 1: Open your Jenkins installed web browser and navigate to the Jenkins URL
(http://localhost:<your configured port>).

Step 2: Access Jenkins web interface Dashboard >> Go to Manage Jenkin

Step 3: Click on the Manage Plugins, and then search for the plugin you want to install from
the Jenkins Update Centre.
How to Install Jenkins Plugins?
Step 3: After your Jenkins Plugin selection >> Click the Install button to confirm the
installation. (Note: You can select multiple plugins at a time.)

Step 4: After installing the Jenkins plugins, you need to restart Jenkins for the changes to
take effect. Click on the logout button in the top right corner of the page to restart the Jenkins.
That’s it! now you can login to Jenkins servers and verify your installed Plugins from Manage
Plugins >> Installed Plugins.
How to Manage Jenkins Plugins?
Update Jenkins Plugins:
Step 1: Open your Jenkins installed web browser and navigate to the Jenkins URL
(http://localhost:<your configured port>).

Step 2: Access Jenkins web interface Dashboard >> Go to Manage Jenkins > Click on the
Manage Plugins >> Click on Updates >> search or select the Plugin that you want to
update then click the Update Now button. Jenkins will check for updates for installed plugin,
and then install any updates that are available.

Uninstall Jenkins Plugins:


Step 1: Open your Jenkins installed web browser and navigate to the Jenkins URL
(http://localhost:<your configured port>).
Step 2: Access Jenkins web interface Dashboard >> Go to Manage Jenkins > Click on the
Manage Plugins >> >> Click on Installed Plugins
Step 3: search or select the Plugin that you want to uninstall >> click the Uninstall button (X)
Jenkins Build Pipeline
A Jenkins pipeline is a set of plug-ins to create automated, recurring workflows that constitute
CI/CD pipelines.

CI/CD pipeline as the backbone of the DevOps approach. This Pipeline is responsible for
building codes, running tests, and deploying new software versions.

What is Continuous Integration (CI)?


Continuous Integration is a practice that integrates code into a shared repository. It uses
automated verifications for the early detection of problems. Continuous Integration doesn't
eliminate bugs but helps in finding and removing them quickly.

What is Continuous Delivery (CD)?


Continuous Delivery is the phase where the changes are made in the code before deploying.
The team in this phase decides what is to be deployed to the customers and when. The final
goal of the pipeline is to make deployments.
Jenkins Build CI/CD Pipeline
Benefits of Pipelines:
•Fast-track the delivery of code to production
•Automate build generation for pull requests, ensuring no syntax errors are merged to the
main branch/repository
•Perform automated unit, sanity, and regression testing
•Create customized automation workflows for different clients, environments, or products.
•Ensure security best practices are followed by performing static code analysis, vulnerability
scanning, and penetration testing on every commit
•Reduce the need for manual maintenance, testing, and deployment, allowing your
developers and DevOps engineers to focus on more productive tasks

Defining Pipeline-as-Code:
•The code that defines a pipeline is written inside a text file, known as the Jenkinsfile.
•The pipeline-as-code model recommends committing the Jenkinsfile to the project
source code repository. This way, a pipeline is modified, reviewed, and versioned like
the rest of the source code.
•It’s also possible to create a pipeline and provide its specification using Jenkins’ web
UI
Jenkins Pipeline-as-Code
pipeline {
agent any
stages {
stage('Build') {
steps {
// compile code
// if successful, move build artifacts to the desired location
}
}
stage('Test') {
steps {
// check if artifacts are present in the correct location
// load test data into the database
// execute the test case
// continue only if tests passed
}
}uio
stage('Deploy') {
steps {
// Fetch tested code and deploy it to production
}
}
}
}

You might also like