0% found this document useful (0 votes)
168 views124 pages

Dev Ops

Here are some key market trends in the DevOps ecosystem: - Containerization: Container technologies like Docker have enabled easier deployment and management of applications across environments. This has been a major enabler of DevOps practices. - Microservices architecture: Breaking applications into smaller, independent services has improved agility, scalability and deployment of applications. Microservices are well suited for containerized environments. - Serverless computing: Serverless platforms allow developers to run code without managing servers. This removes infrastructure management overhead and allows teams to focus on code. - Infrastructure as code: Tools like Terraform allow defining and provisioning infrastructure using code. This brings infrastructure under version control and allows treating it as code.

Uploaded by

sahaj pareek
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
168 views124 pages

Dev Ops

Here are some key market trends in the DevOps ecosystem: - Containerization: Container technologies like Docker have enabled easier deployment and management of applications across environments. This has been a major enabler of DevOps practices. - Microservices architecture: Breaking applications into smaller, independent services has improved agility, scalability and deployment of applications. Microservices are well suited for containerized environments. - Serverless computing: Serverless platforms allow developers to run code without managing servers. This removes infrastructure management overhead and allows teams to focus on code. - Infrastructure as code: Tools like Terraform allow defining and provisioning infrastructure using code. This brings infrastructure under version control and allows treating it as code.

Uploaded by

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

Class 1

Detail out the course


Introduction
and Course
Hand-out
Perform activity – Create 2
briefing project team, demo on process
of following SDLC process
Class 2
SDLC also called as Software Development Process

Process followed by an IT organization to build a


Software software

Development Framework which details the various tasks


Life Cycle performed at every step

Objective is to high quality software as an end


product

Product must satisfy the customers expectation


SDLC Phases

Requirement
Initiation Planning Design
Analysis

Maintenance Implementation Testing Development


First Process Model introduced in SDLC

Follows a linear sequential flow

Waterfall
Model Divided into various phases
The output of one phase acts as the input for
the next phase

Water flow cannot be turned back once flown


over the cliff edge
Disadvantage of Waterfall Model

•Working software is produced almost at the end

•Lot of uncertainty causes high amount of risk

•Not a good model for complex and long ongoing projects

•Not a recommended model for moderate to high risk of changing


requirements kind of projects

•Difficult or cannot accommodate changing requirements


Agile Methodology
• An iterative project management and software development approach

• Helps development team to release features to their customers at fast pace

AGILE
Plan Design Develop Test Release Feedback

• Agile team produces software in small amount and incrementally instead of a big large release

• Constant and better collaboration with stakeholders and continuous improvement at every stage

• Offers flexibility, adaptability to change, and high level of customer input


DevOps comes to rescue

Developer Operations

SOFTWARE COMBINATION OF TWO ONE TEAM TO HANDLE ENCOURAGES IMPROVES


DEVELOPMENT AND IT WORDS - THE COMPLETE AUTOMATING THE ORGANIZATION’S
OPERATIONS PROCESS DEVELOPMENT AND APPLICATION LIFECYCLE, DEPLOYMENT, CAPABILITY TO DELIVER
OPERATION FROM DEVELOPMENT CONFIGURATION, SOFTWARE
TO TESTING, MONITORING, AND APPLICATIONS AND
DEPLOYMENT, MANAGEMENT OF SERVICES
AND OPERATIONS APPLICATIONS
Advantages of DevOps

Better approach for Responds faster to the Increases business


Helps to become more
quick application market changes to profit by reducing
agile and able to deliver
development and improve business software delivery time
applications faster
deployment growth and transportation costs

DevOps clears the DevOps means


DevOps simplifies
descriptive process, Improves customer collective responsibility,
collaboration and places
which gives clarity on experience and better team
all tools in the cloud for
product development satisfaction engagement and
customers to access
and delivery productivity
DevOps professional or expert's
developers are less available

Developing with DevOps is bit expensive

Disadvantages
of DevOps Hard to manage adoption of new DevOps
technologies in short time

Lack of DevOps knowledge can lead to


problem in the continuous integration of
automation
Class 3
Discussion of Project and Assignment

•Prepare maven-based java project may be hello world


•Add it into Git
•Maven build
•Junit creation and executing it via maven
•SonarQube integration via maven
•Jenkins job
Class 4
DevOps Pipeline

•DevOps pipeline is a set of tools and automated processes which enables


engineering team to have close interactions while building a software

•Main purpose of DevOps pipeline is to enable automation and that should be


continuous. For example, continuous integration, continuous
delivery/deployment (CI/CD), continuous feedback, and continuous operations

•DevOps pipeline consists of various phases, and it tries to get rid of manual
operations as much possible in these phases

•It can vary project to project

•It may include one or more manual gates that require human intervention before
it proceed to next phase
Continuous Development
Continuous Integration
Continuous Testing
Lifecycle of Continuous Monitoring
DevOps
Continuous Feedback
Continuous Deployment
Continuous Operations
The project goal and plans are created
during planning.

Based on planning, the code is developed

Continuous by developers.

Development Developers use IDE (Integrated


Development Environment) or source code
editor to write code.

Developers use source code management


tool.
The objective of this phase is to perform testing
on the software.

Testing phase should also be automated and

Continuous continuous in nature.

Testing Tools such as TestNG, JUnit, Selenium, JMeter


etc. can be used by testing team to thoroughly
test application functionality.

Minimize a lot of time and effort for executing


the test cases instead of performing it
manually.
It means code is committed by developers
frequently, every commit is compiled, unit tested,
integration tested, code reviewed, and packaged.

Continuous It helps in early detection of problems if any exists

Integration
in the code.

One of the popular tool, Jenkins, can be used to


perform automation in this phase. Any change in
the Git repository, Jenkins fetches the updated
code and prepares a build of that code and
package it. This build is then forwarded to the test
server or the production server.
In this phase the artifact, the compiled tested
bundled code, is deployed on the production server.

Continuous In this phase, specifically for production deployment,

Deployment
a manual gate is preferred.

In other non-production environments, the


deployment can be automated and continuous.
In this phase the application is continuously
monitored for its performance.

Continuous Logs, metrices, events etc. are recorded and

Monitoring
analyzed for application performance and issues.

Operations team setup the tools and provide access


to developers to various metrices, logs which
developers to closely check the health of the
application.
It consists of two types of feedback – end user
feedback and application monitoring feedback.

Continuous End user provides their feedback based on their

Feedback
experiences while browsing the application.

Automated monitoring tools also provide vital


information and alerts on the application
performance and issues when used by end user.
DevOps Pipeline

Continuous Integration Manual


Switch
Acceptance Deploy to Deploy to
Source Code Build Test
Test Staging Production
Continuous Delivery

Acceptance Deploy to No Deploy to


Source Code Build Test
Test Staging Switch Production
Continuous Deployment
DevOps Lifecycle
Class 5
DevOps
Ecosystem
Market trends of DevOps
Serverless Microservices
Containerization
computing architecture

DevSecOps Low-code apps GitOps

Infrastructure as a
Automation
code
1. Containerization

Container technologies has made an impact in the rise of DevOps. Containers are lightweight, self-
contained environments that make it easier to host and manage web applications. By 2023,
Gartner expects 70% of companies to run two or more containerized applications. As more and
more apps will be developed, DevOps will be needed to deal with the system complexities.

Market 2. Serverless computing

trends of The concept of serverless computing has emerged as a new and exciting approach to deploying

DevOps software and other services. Serverless computing removes server maintenance, system updates
workload from the developers. Serverless computing generates code for DevOps pipelines without
the need for a host to build, test, and deploy.

3. Microservices Architecture

Microservices architecture focuses on building smaller and manageable applications than a large
monolithic applications. It encourages shorter software release intervals. Along with robust DevOps
processes, it becomes easier to build applications faster.
4. DevSecOps

Building internet facing application, security becomes a major concern for organizations.
DevSecOps integrates best practices in software development, delivery, and operations with an
emphasis on security and observability, so the risks and vulnerabilities in the given applications are
reduced. DevSecOps helps to close the security knowledge gap between IT and business. It
supports the early detection of cyber risks and the reduction of costs associated with their
remediation.

Market 5. Low-code apps

trends of Low-code platforms allow you to build apps without coding knowledge. This allows non-technical
people to contribute to software development through a visual interface that manages the entire
app development process. It allows users to build their own workflows and logic by dragging and

DevOps dropping elements. This trend in DevOps speeds up the entire development and deployment
process by creating simple and user-friendly apps.

6. GitOps

GitOps is one of the ways to implement and manage Kubernetes clusters. By releasing incremental
updates, continuous delivery enables development teams to build, test, and deploy software more
quickly. It is essential that a Kubernetes continuous integration and runtime pipeline be capable of
reading and writing files to Git, updating container repositories, and loading containers. Version
control for configuration changes, as well as real-time monitoring and alerting are all possible with
GitOps, allowing the business to better manage infrastructure.
7. Infrastructure as a Code

Market Infrastructure as a Code automates resource management and provisioning by using code, instead
of using configuration tools. DevOps teams may provide and control all parts of the environment,
including VMs, operating systems, containers, application configuration, storage, networking, and

trends of
connections between multiple components, using infrastructure as code.

DevOps 8. Automation

DevOps encourages towards automation and help businesses become more efficient, responsive,
and transparent to their customers. In order to meet the increasing demands and quick software
turn around, a high level of multitasking skilled development team is expected and the only way to
achieve this is to adopt and accelerate automation. Automation of time-consuming long processes
enables development team to focus on other critical requirements.
DevOps Roles, Responsibilities, Skills

DevOps engineer’s work is


a full-time job.

DevOps engineers should


have problem-solving and
quick-learning soft skill. Able to
perform Manage
Improve Ensuring
system project
Increase quality and Analyze, critical
They are responsible for troubleshooti effectively
project reduce design and resolution of
the production and ng and through
visibility development evaluate system issues
maintenance of a software problem- open,
through cost with automation by using the
application’s platform. solving standards-
traceability. collaboration scripts. best security
across based
. solutions.
platform and platforms.
application.
Class 6
Git

•Open-source distributed version control system.

•It is developed to co-ordinate the work among the developers.

•It allows to track and work together with project team members at the same workspace.

•It provides backups for uncertainty.

•Complete change history of a file.

•Developers can compare earlier versions of the code with an older version to fix the
mistakes.
Git Repository

•Repository is the storage location where all files, packages/folders are kept.

•Two types of repositories – Local and Remote

•Remote repository is on the server and local repository is on developers local PC.

•Local repository is the copy of remote repository.

•Developers works on their local repository and push their work to remote repository.
Remote Repository

Server

Remote Repository

Developer 2 Developer 3
Developer 1
Local Repository Local Repository
Local Repository
Git Installation
Follow the installation wizard and click on next next button.
Download https://github.com/git-for-
windows/git/releases/download/v2.3
7.2.windows.2/Git-2.37.2.2-64-bit.exe

Double click on Git installer Click on Install button


Create Git Repository using Git
Click on Create New Repository
Git Branches
There are different types of branches in a project. According to
the standard branching strategy and release management,
there can be following types of branches:
•Master
•Develop
•Hotfixes
•Release branches
•Feature branches
Every branch has its meaning and standard. Let's understand
each branch and its usage.

The Main Branches


Two of the branching model's branches are considered as main
branches of the project. These branches are as follows:
•master
•develop
Class 7
Git config
Command
•Git config command
•This command configures the user.
The Git config command is the first
and necessary command used on the
Git command line. This command
sets the author name and email
address to be used with your
commits.
•Syntax
•$ git config --
global user.name “Rajender Singh"
•$ git config --
global user.email “Rajender.Choudhar
[email protected]"
•Git Init command
•This command is used to create a local repository.

Git init Command


•Syntax
•$ git init demo
•The init command will initialize an empty repository. See the below screenshot.

Create Git
Repository using •Click on Create Repository option

GitHub
•Git clone command

Git clone •This command is used to make a copy of a repository from an existing URL. If I want a local copy of my repository
from GitHub, this command allows creating a local copy of that repository on your local directory from the
repository URL.

Command •Syntax
•$ git clone URL
Create a sample
Java Project
•Create a sample Java project
using any IDE.
Git add
Command
•Git add command
•This command is used to add
one or more files to staging
(Index) area.
•Syntax
•To add one file
•$ git add Filename

•To add more than one file


•$ git add *
Git status
Command
•Git Status
•This command is used to determine
the status of each file in the project.
It provides which changes have been
staged, which haven’t, or being
tracked by Git. It also lists the files
that are changed and still need to
add or commit.

•Syntax
•To check the status of the files
•$ git status
Git Files Status
Tracked files are those files which Git knows. These are referred as tracked files. The files were present in the last snapshot,
as well as any newly staged files; they can be unmodified, modified, or staged.
Remaining files are Untracked files. Any file in the working directory that were not in the last snapshot and are not in the
staging area. When we first clone a repository, all of our files will be tracked and unmodified because Git just checked them
out and you haven’t edited anything.
As we edit files, Git sees them as modified, because we have changed them since the last commit. As we work, we
selectively stage these modified files and then commit all those staged changes

Untracked Unmodified Modified Staged

git add
Edit an existing file
rm filename
git add
(delete a file)
git commit
Git Cheat Sheet
Git Common Commands
Git Branch Command
This command lists all the branches available in the repository.
Syntax
1.$ git branch

Git Merge Command


This command is used to merge the specified branch?s history into the current branch.
Syntax
1.$ git merge BranchName

Git log Command


This command is used to check the commit history.
Syntax
1.$ git log

By default, if no argument passed, Git log shows the most recent commits first. We can limit the number of log entries displayed by passing a number as an option, such as -3 to show only the last three
Git Token Setting
Login to Github.
Click on Profile  Settings - Developer Settings - Personal access tokens - Tokens Classic - Generate new tokens

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

During git push command this token will be used as auth token instead of credentials.s
Class 8
Git Branching
Model
•Git Flow / Git Branching Model
•Git flow is the set of guidelines that
developers can follow when using
Git. We cannot say these guidelines
as rules. These are not the rules; it is
a standard for an ideal project. So
that a developer would easily
understand the things.
•It is referred to as Branching
Model by the developers and works
as a central repository for a project.
Developers work and push their work
to different branches of the main
repository.
Git Branches
There are different types of branches in a project. According to
the standard branching strategy and release management,
there can be following types of branches:
•Master
•Develop
•Hotfixes
•Release branches
•Feature branches
Every branch has its meaning and standard. Let's understand
each branch and its usage.

The Main Branches


Two of the branching model's branches are considered as main
branches of the project. These branches are as follows:
•master
•develop
Git Branches
Master Branch
The master branch is the main branch of the project that contains all the history of final changes. Every developer must be used to the
master branch. The master branch contains the source code of HEAD that always reflects a final version of the project.
Your local repository has its master branch that always up to date with the master of a remote repository.
It is suggested not to mess with the master. If you edited the master branch of a group project, your changes would affect everyone else,
and very quickly, there will be merge conflicts.
Develop Branch
It is parallel to the master branch. It is also considered as the main branch of the project. This branch contains the latest delivered
development changes for the next release. It has the final source code for the release. It is also called as a "integration branch."
When the develop branch reaches a stable point and is ready to release, it should be merged with master and tagged with a release
version.
Supportive Branches
The development model needs a variety of supporting branches for the parallel development, tracking of features, assist in quick fixing
and release, and other problems. These branches have a limited lifetime and are removed after the uses.
The different types of supportive branches, we may use are as follows:
•Feature branches
•Release branches
•Hotfix branches
Each of these branches is made for a specific purpose and have some merge targets. These branches are significant for a technical
perspective.
Git Branches
Feature Branches
Feature branches can be considered as topic branches. It is used to develop a
new feature for the next version of the project. The existence of this branch is
limited; it is deleted after its feature has been merged with develop branch.
Git Branches
Release Branches
The release branch is created for the support of a new version release. Senior developers will create a release
branch. The release branch will contain the predetermined amount of the feature branch. The release branch should
be deployed to a staging server for testing.
Developers are allowed for minor bug fixing and preparing meta-data for a release on this branch. After all these
tasks, it can be merged with the develop branch.

When all the targeted features are created, then it can be merged with the develop branch. Some usual standard of
the release branch are as follows:
•Generally, senior developers will create a release branch.
•The release branch will contain the predetermined amount of the feature branch.
•The release branch should be deployed to a staging server for testing.
•Any bugs that need to be improved must be addressed at the release branch.
•The release branch must have to be merged back into developing as well as the master branch.
•After merging, the release branch with the develop branch must be tagged with a version number.
Git Branches
Hotfix Branches
Hotfix branches are like Release branches; both are created for
a new production release.
The hotfix branches arise due to immediate action on the
project. In case of a critical bug in a production version, a hotfix
branch may branch off in your project. After fixing the bug, this
branch can be merged with the master branch with a tag.
Class 9
Jenkins is an open-source continuous integration tool.

It helps to automate the software development process making it


continuous and reduces manual effort.

Jenkins Jenkins achieves CI (Continuous Integration) with the help of

Overview
plugins.

Jenkins automates day-to-day tasks such as checking out the


sources from source control, building, code analysis, and different
levels of testing and deployment.

Jenkins runs these tasks each time a developer has changed the
source code, can detect any defects much faster meaning that you
maintain applications' quality and reduce time to market.
Jenkins has very large community that
contributes to it regularly.

There is no subscription cost as it is free and


open source.
Jenkins
Benefit It is highly configurable and has a support for
many plugins.

It supports multiple platforms. It is platform


independent. It is available for different
operating systems like Windows or Linux or OSX.
Jenkins Continuous Integration Workflow

Developer

Compile Build Test


Developer Code Repository Deploy

Developer
Jenkins Installation
• Download Jenkins from https://www.jenkins.io/

• Get Jenkins war file

• Open command prompt and execute java –jar Jenkins.war


Jenkins Starting
Jenkins Launching
• Open chrome and type URL http://localhost:8080/

• Enter the password provided in command prompt incase prompted


Jenkins Launching

• Choose first option Install Suggested plugins


Jenkins Launching

• Close pop up
Class 10
Jenkins Management
• Click on the "Manage Jenkins" option from the left hand of the Jenkins Dashboard page to manage Jenkins.

• Jenkins Management has many options as mentioned below:


• Configure System
• Configure Global Security
• Global Tool Configuration
• Manage Plugins
• System Information
• System Log
• Load Statistics
• Jenkins CLI
• Reload Configuration from Disk
• Script Console
• Manage Nodes
• About Jenkins
• Manage Old Data and
• Prepare for Shutdown
Jenkins Master and Slave Architecture
• A Jenkins master comes with the basic installation of Jenkins, and in this configuration, the master handles
all the tasks for your build system.

• If you are working on multiple projects, you may run multiple jobs on each and every project. Some projects
need to run on some nodes, and in this process, we need to configure slaves. Jenkins slaves connect to the
Jenkins master using the Java Network Launch Protocol.

• The Jenkins master acts to schedule the jobs and assign slaves and send builds to slaves to execute the jobs.

• It will also monitor the slave state (offline or online) and getting back the build result responses from slaves
and the display build results on the console output. The workload of building jobs is delegated to multiple
slaves.
Jenkins
(Master)

Jenkins Jenkins Jenkins


(Slave 1) (Slave 2) (Slave 3)
Prepare Slave Nodes
• Before adding a slave node to the Jenkins master we need to prepare the node. We need to install Java on the
slave node. Jenkins will install a client program on the slave node. To run the client program we need to
install the same Java version we used to install on Jenkins master.
Configure Jenkins Master & Slave Nodes
• Log in to the Jenkins console via the browser
• click on "Manage Jenkins"
• click on "Manage Nodes".
• click on "New Node".
• Select Permanent Agent and click the OK button.
• Click create button
Configure Jenkins Master & Slave Nodes
• In the remote root directory field enter a path in the
slave node.

• Enter the slave nodes IP address in the field in Host field


on selecting launch method as launch agent agents via
SSH.

• Click the Save button


Update Jenkins Generated Admin Password
• Login with default admin and password into Jenkins.
• Click on right top side Admin profile image.
• Click on Configure link.
• Update password and confirm password.
• Click on Apply and Save.
First Jenkins Job
• Login to Jenkins.
• Click on New Item.
• Enter job name and select Freestyle Project.
• Click OK button.
• Click on Configure job.
• Goto Build Steps section and select Execute
Windows batch command.
• Click on Save button.
• Click on Build Now link of this new job to trigger
the build.
Copy Existing Jenkins Job
• Login to Jenkins.
• Click on New Item. Enter job name. Scroll down the page and
click in Copy from option.
• Type an existing job name which is required to be used for
reference. Click on OK.
• Goto Configure option of the newly created job Job 2. Notice it
has all the configurations present in Job 1.
• Now configure the job to modify its description and other
needed details.
Dependent Jenkins Job
• Set up a trigger so that when some other
projects finish building, a new build is scheduled
for this project.

• Select Job 2 and click on configure option.


• Goto Build Triggers option and select Build after
other projects are built.
• Type job name “Job 1” in Project to watch.
• Click Save.

• Now build Job 1.


• Notice first Job 1 completed successfully it
triggers Job 2 automatically.
Build History View
• It displays a list of your past builds, time since build and the status of each build.
• Go to Jenkins dashboard page.
• Select Build history option in the left side.
Trigger Jobs Periodically
• Select a Job and click on configure.

• Jenkins use cron expression which has below format:


• Minutes in one hour 0-59
• Hours in a day 0-23
• Day in a month 1-31
• Month in a year 1-12
• Day of the week 0-7 where 0 and 7 are Sunday
Class 11
Install Delivery Pipeline
• Start Jenkins by executing command on command prompt.
Java –jar Jenkins.war

• Open browser and provide URL http://localhost:8080/


• Login screen will appear.
• Enter username and password and click sign in button.

• Click on Manage Jenkins. Click Plugins.


• Click on Available tab. Search Delivery pipeline. Select Plugin and install.
New Job
• Go to dashboard. Click New Item. /Enter item • Provide configuration.
name and select freestyle project. Click ok button.

• Go to dashboard
More Jobs
• Similarly prepare 2 more jobs.

• Go to BuildJob1. Click on Build Now.


Configure • Edit Job configuration. Select Build after other projects are
built. Specify the BuildJob1.
Dependent Jobs
Create Delivery Pipeline View
• Go to dashboard. On Dashboard near All link, • Enter name. Select Delivery Pipeline View option
there is “+”. Click on + New View button. and click create button.
Create Delivery Pipeline View
• Click Add button under Pipelines  Components
option.
Delivery Pipeline View
• Go to dashboard. Click on DeliveryPipeline1 tab.
Execute Chained Dependent Jobs
• Execute BuildJob1 by clicking • Verify dependent chained jobs build history.
Build Now. Check build history.

• Notice that executing only first job Buildjob1 will trigger the other two jobs TestJob1 and DeployJob1 automatically
one after other on their completion.
Verify Delivery Pipeline View
• Go to dashboard. Click on DeliveryPipeline1 tab.
Add More Features to Pipeline View
• Go to Dashboard. Click
DeliveryPipeline1 view. Click on
Edit View.

• Modify Number of pipeline


instances per pipeline from 3 to
4. It will show 4 pipelines
instances for each pipeline.

• Select Enable start of new


pipeline build option. It will
allow starting a new pipeline
run from the delivery pipeline
view.

• Select Enable rebuild option. It


will allow rerunning a task from
the delivery pipeline view.

• Select Show total build time.


Class 12
Pipeline as a Code
• Pipeline as code is a way by which one can define software delivery pipelines as code, stored and versioned in
a source repository.

• Projects must contain a file named Jenkinsfile in the repository root, which contains a "Pipeline script.“

• Presence of the Jenkinsfile in the root of a repository makes it eligible for Jenkins to automatically manage and
execute jobs based on repository branches.

• JenkinsFile contains the steps needed for running a Jenkins pipeline


Jenkins File
• The first block is pipeline. It is the main block that contains the entire declaration of a pipeline.

• Pipeline block will have stages, stage and steps block.

• declarative pipeline structure :

pipeline {
agent any

stages {
stage('Hello') {
steps { echo 'Hello World' }
}
}
}

• pipeline – contains the whole pipeline


• agent – defines the machine that will handle this pipeline
• stages – declares the stages of the pipeline
• steps – small operations inside a particular stage
Simple Scripted Pipeline
• Click New item. Enter a name and select Pipeline. Write a simple script.
• Build Now
Setup Maven in Jenkins
• Click Manage Jenkins. Click Tools.

• Add maven details.

• Click Apply and Save button.


Setup Git Plugin in Jenkins
• Click Manage Jenkins. Click Plugins.

• Enter Git.

• Select Git option and click on Install without


restart.

• OR

• If Git is already installed then setup git as


per given screenshot.
Create New GitHub Repository
• Create a repo.

• Open git bash.


Initialize Repository
• Run git init DemoJenkinsfile command.
Create Java Project & Jenkinsfile
• Create a sample Java project. • Add Jenkins file.

• Add code to GitHub


Create Pipeline in Jenkins
• Go to Jenkins and click New Item.

• Enter name DemoJenkinsPipeline, select Pipeline and click ok.

• Select ‘Pipeline from SCM’ from pipeline section.


Create Pipeline in Jenkins
• Click on Build Now.

• Click on logs on the stage.


Class 13
Maven
• Maven is a powerful project management tool that is based on POM (project object model).

• Maven is an open-source build tool and written in Java.

• It is used for projects build, dependency and documentation.

• Maven is declarative, everything you define in the pom.xml file.

• It provides a framework which has a life cycle.

• It performs compilation of Source Code, Running Tests (unit tests and functional tests), Packaging the results
into JAR’s,WAR’s,etc., Upload the packages to remote repo’s (Nexus, Artifactory).

• Some popular IDEs supporting development with Maven Framework like Eclipse, IntelliJ IDEA, Jbuilder,
Spring Tool Suite etc.
Maven Installation
• To install maven on windows,
Download maven from
https://maven.apache.org/dow
nload.cgi
and extract it.

• Right click on MyComputer ->


properties -> Advanced System
Settings -> Environment
variables -> click new button

• Add MAVEN_HOME (the path


where maven is installed) in
environment variable
• Add maven path (the path of
bin directory where maven is
installed) in Path environment
variable.

• Verify maven by executing


command on command prompt
Maven Repository
• Maven repositories refer to the directories of
packaged JAR files that contain metadata.
The metadata refers to the POM files
relevant to each project. This metadata is
what enables Maven to download
dependencies.

• Maven has two types of repositories - local,


central. Maven
Repository

Local Central
Repository Repository

It is a directory on the computer where Maven runs. It It refers to any other type of repository, accessed by a variety
caches remote downloads and contains temporary of protocols such as file:// and https:// present on a web
build artifacts that you have not yet released. server, which is used when Maven needs to download
dependencies. Whenever dependency is required from the
remote repository, it is first downloaded to the local
repository, and then used.
Local Repository
• Default local repository is created under %USER_HOME%/.m2 directory.

• There is a way to change the location of maven local repository. Update settings.xml file located in
MAVEN_HOME/conf/settings.xml, for example: C:\apache-maven-3.8.6-bin\apache-maven-3.8.6\conf.

• Default local repository is created under %USER_HOME%/.m2 directory.

• There is a way to change the location of maven local repository. Update settings.xml file located in
MAVEN_HOME/conf/settings.xml, for example: C:\apache-maven-3.8.6-bin\apache-maven-3.8.6\conf.
Central Repository
• Maven central repository is located on the web. It has been created by the apache maven community itself.

• It contains a large number of commonly used libraries.

• When Maven does not find any dependency in local repository, it starts searching in central repository.

• The path of central repository is: http://repo1.maven.org/maven2/. It requires internet access to be searched.

• Sometimes, Maven does not find a mentioned dependency in central repository as well. It then stops the build
process and output error message to console. To prevent such situation, Maven provides concept of Remote
Repository, which is developer's own custom repository containing required libraries or other project jars.

• For example, using below mentioned POM.xml, Maven will download dependency (not available in central
repository) from Remote Repositories mentioned in the same pom.xml.
<repositories>
<repository>
<id>companyname.lib1</id>
<url>http://download.companyname.org/maven2/lib1</url>
</repository>
<repository>
</repositories>
Maven Build Life Cycle
Compile
• Compile the source code of the project.

Test-compile
• Compile the test source code into the test destination directory.

Test
• Run tests using a suitable unit testing framework (Junit is one).

Package
• Take the compiled code and package it in its distributable format, such as a JAR, WAR, or EAR file.

Integration-test
• Process and deploy the package, if necessary, into an environment where integration tests can be run.

Verify
• Run any check-ups to verify the package is valid and meets quality criteria.

Install
• Install the package into the local repository, which can be used as a dependency in other projects locally.

Deploy
• Copies the final package to the remote repository for sharing with other developers and projects.
Maven Project Structure
• Maven uses a convention for project folder structure. If we follow that, we need not describe in our configuration
setting, what is located where. Maven knows from where to pick the source files, test cases etc. Following is a
snapshot from a Maven project, and it shows the project structure,

• rootproj.
├── pom.xml
└── src
├── main
│ └── java
│ └── com
│ └── ecom
│ └── App.java
└── test
└── java
└── com
└── ecom
└── AppTest.java
9 directories, 3 files
Class 14
Maven Project Object Model overview
• To configure the Maven, you need to use Project Object Model, which is stored in a pom.xml-file

• POM stands for Project Object Model. It is fundamental unit of work in Maven. It is an XML file that resides in the
base directory of the project as pom.xml.And has all the configuration settings for the project build.

• Generally we define the project dependencies (Ex: dependent jar files for a project), maven plugins to execute and
project description /version etc.
POM File Elements
• Simplest pom.xml should have 4 important information.

• modelVersion-4.0.0 (POM version for Maven 2 and is always required)


• groupId —will identify your project uniquely across all projects, ex:ebs.obill.webs, com.companyname.project
• artifactId — is the name of the jar without version(keeping in mind that it should be jar-name friendly)
• version — if you distribute it then you can choose any typical version with numbers and dots (1.0, 1.1, 1.0.1, …)

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>my-app</artifactId>
<version>1</version>

</project>
• There is an element available for declaring dependencies in project pom.xml This is used to
define the dependencies that will be used by the project. Maven will look for these dependencies
when executing in the local maven repository. If not found, then Maven will download those
dependencies from the remote repository and store it in the local maven repository. Example
declaring junit and log4j as project dependencies,

•<dependencies>
• <dependency>
• <groupId>junit</groupId>

Maven
• <artifactId>junit</artifactId>
• <version>3.8.1</version>
• <scope>test</scope>

Dependency • </dependency>
• <dependency>
• <groupId>log4j</groupId>
• <artifactId>log4j</artifactId>
• <version>1.2.12</version>
• <scope>compile</scope>
• </dependency>
• </dependencies>

•scope — describes under which context this dependency will be used.


Maven Plugins
• All the execution in Maven is done by plugins. A plugin is mapped to a phase and executed as part of it. A phase is
mapped to multiple goals. Those goals are executed by a plugin. We can directly invoke a specific goal while Maven
execution. A plugin configuration can be modified using the plugin declaration.

• An example for Maven plugin is ‘compiler’, it compiles the java source code. This compiler plugin has two goals
compiler:compile and compiler:testCompile.

• Using the configuration element, we can supply arguments to the plugin.


<build>
<finalName>springexcelexport</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin> </plugins>
</build>
Jenkins
Maven Job
• Go to Dashboard  Manage
Jenkins  Global Tool
Configuration
Class 15
• Refer demo using STS IDE and command prompt.

Maven
webapp
structure,
run, deploy
SonarQube Installation
• Install sonarqube server from https://www.sonarqube.org/downloads/

• Extract the downloaded file.


Launch SonarQube
• Execute StartSonar.bat file from command prompt.

• Type URL http://localhost:9000/ in the browser to launch SonarQube. Enter admin as both login and password.
Update password on first login. Let’s say sonar.
SonarQube Token
• Go to Administration  Security  Users

• Click on Tokens. Provide project name in Name textbox and click on Generate button.
squ_988144d1edd99598ca9d0cd5b0c2c991f99a12de
SonarQube Webhook
• As Jenkins and SonarQube are running in separately,
we need to create a Webhook at SonarQube Server
so that both can communicate with each other.

• Login to SonarQube. Go to global


configuration: Administration > General Settings >
Security, setting “Enable local webhooks validation”
to false.

• Now go to Dashboard > Administrator >


Configuration > Webhook.

• Click the Create button on the right side to create a


webhook.

• Provide name, URL as ‘JENKINS-URL/sonarqube-


webhook/’ and a secret (DemoJenkinsfile) for
connection with Jenkins. Click on the Create button
to save.
Jenkins Setup for SonarQube
• Login to Jenkins. Go to Dashboard > Manage • Go to the Manage Jenkins page and select
Jenkins > Plugins. Install SonarQube Scanner Global Tool Configuration. Add below
plugin in Jenkins. details under SonarQube Scanner.
Add SonarQube Server Generated Access Token in Jenkins
Go to Dashboard > Manage Jenkins > Manage Credentials > Click on Jenkins line item under Stores scoped to Jenkins
section. Click on Global credentials (unrestricted) hyperlink.

• Click on Add Credentials. Select “Secret Text” field


under Kind. In the Secret field, paste the generated
token from SonarQube that you previously created.
Add SonarQube Server Installation in Jenkins
• Add the SonarQube server to the Jenkins environment. Go to Dashboard > Manage Jenkins > System.

• Add below details under SonarQube servers section. Add SonarQube authentication token in the Server authentication
token drop down.

• Click on Advanced button and add SonarQube webhook token to Jenkins.


Sonar Properties in Maven Project
• Add sonar-project.properties file in root folder of the project

• Update Jenkinsfile for sonar analysis stage

You might also like