Teja Devops
Teja Devops
Exercise-1
Software engineering and Agile software development
1.Get an understanding of the stages in software development lifecycle, the process models,
values and principles of agility and the need for agile software development. This will enable
you to work in projects following an agile approach to software development
Aim: understanding of the stages in software development lifecycle, the process models, values
and principles of agility and the need for agile software development
Procedure:
Software Development Life Cycle (SDLC) is a framework that defines the steps involved in
the development of software at each phase. It covers the detailed plan for building, deploying
and maintaining the software. SDLC defines the complete cycle of development i.e. all the
tasks involved in planning, creating, testing, and deploying a Software Product.
SDLC Cycle
Name :K.TEJASWAROOP
Roll no : 21HQ1A0529
Subject : CICD
1
AVANTHI’S RESEARCH AND TECHNOLOGICALACADEMY
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
1.Waterfall Model
Waterfall model is the very first model that is used in SDLC. It is also known as the linear
sequential model.In this model, the outcome of one phase is the input for the next phase.
Development of the next phase starts only when the previous phase is complete.
2.V-Shaped Model
V- Model is also known as Verification and Validation Model. In this model Verification &
Validation goes hand in hand i.e. development and testing goes parallel. V model And Waterfall
model are the same except that the test planning and testing start at an early stage in V-Model.
Name :TEJASWAROOP
Roll no : 21HQ1A0529
Subject : CICD
2
AVANTHI’S RESEARCH AND TECHNOLOGICALACADEMY
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
3. Prototype Model
The prototype model is a model in which the prototype is developed prior to the actual
software.Prototype models have limited functional capabilities and inefficient performance
when compared to the actual software. Dummy functions are used to create prototypes. This is
a valuable mechanism for understanding the customers’ needs.
4. Spiral Model
The Spiral Model includes iterative and prototype approach.Spiral model phases are followed
in the iterations. The loops in the model represent the phase of the SDLC process i.e. the
innermost loop is of requirement gathering & analysis which follows the Planning, Risk
analysis, development, and evaluation. Next loop is Designing followed by Implementation &
then testing.
Name :TEJASWAROOP
Roll no : 21HQ1A0529
Subject : CICD
3
AVANTHI’S RESEARCH AND TECHNOLOGICALACADEMY
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
5. Iterative Model
Iterative process starts with a simple implementation of a subset of the software requirements
and iteratively enhances the evolving versions until the full system is implemented. At each
iteration, design modifications are made and new functional capabilities are added. The basic
idea behind this method is to develop a system through repeated cycles (iterative) and in smaller
portions at a time (incremental).
The Big Bang Model comprises of focusing all the possible resources in the software
development and coding, with very little or no planning. The requirements are understood and
implemented as they come. Any changes required may or may not need to revamp the complete
software.
This model is ideal for small projects with one or two developers working together and is also
useful for academic or practice projects. It is an ideal model for the product where requirements
are not well understood and the final release date is not given.
Name :TEJASWAROOP
Roll no : 21HQ1A0529
Subject : CICD
4
AVANTHI’S RESEARCH AND TECHNOLOGICALACADEMY
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
7. Agile model
Agile model believes that every project needs to be handled differently and the existing
methods need to be tailored to best suit the project requirements. In Agile, the tasks are divided
to time boxes (small time frames) to deliver specific features for a release.
AgilityPrinciples:
The Agile Alliance defines twelve lightness principles for those that need to attain agility:
1. Our highest priority is to satisfy the client through early and continuous delivery of valuable
computer software.
2. Welcome dynamical necessities, even late in development. Agile processes harness modification
for the customer’s competitive advantage.
3. Deliver operating computer software often, from a pair of weeks to a couple of months, with a
preference to the shorter timescale.
4. Business individuals and developers should work along daily throughout the project.
5. The build comes around actuated people. offer them the setting and support they have, and trust
them to urge the task done.
6. the foremost economical and effective methodology of conveyancing info to and among a
development team is face-to-face speech.
Name :TEJASWAROOP
Roll no : 21HQ1A0529
Subject : CICD
5
AVANTHI’S RESEARCH AND TECHNOLOGICALACADEMY
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
8. Agile processes promote property development. The sponsors, developers, and users got to be
able to maintain a relentless pace indefinitely.
11. the most effective architectures, necessities, and styles emerge from self– organizing groups.
12. At regular intervals, the team reflects on a way to become simpler, then tunes and adjusts its
behavior consequently.
Name :TEJASWAROOP
Roll no : 21HQ1A0529
Subject : CICD
6
AVANTHI’S RESEARCH AND TECHNOLOGICALACADEMY
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
Exercise-2
Extreme programming (XP) is one of the most important software development frameworks of
Agile models. It is used to improve software quality and responsiveness to customer
requirements. The extreme programming model recommends taking the best practices that have
worked well in the past in program development projects to extreme levels.
Good practices need to be practiced in extreme programming: Some of the good practices
that have been recognized in the extreme programming model and suggested to maximize their
use are given below:
Code Review: Code review detects and corrects errors efficiently. It suggests pair
programming as coding and reviewing of written code carried out by a pair of programmers
who switch their works between them every hour
.
Testing: Testing code helps to remove errors and improves its reliability. XP suggests testdriven
development (TDD) to continually write and execute test cases. In the TDD approach, test
cases are written even before any code is written.
Simplicity: Simplicity makes it easier to develop good quality code as well as to test and debug
it.
Design: Good quality design is important to develop good quality software. So, everybody
should design daily.
Name :TEJASWAROOP
Roll no : 21HQ1A0529
Subject : CICD
7
AVANTHI’S RESEARCH AND TECHNOLOGICALACADEMY
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
XP is based on the frequent iteration through which the developers implement User Stories.
User stories are simple and informal statements of the customer about the functionalities
needed. A User Story is a conventional description by the user of a feature of the required
system. It does not mention finer details such as the different scenarios that can occur. Based
on User stories, the project team proposes Metaphors.
Coding: The concept of coding which is used in the XP model is slightly different from
traditional coding. Here, the coding activity includes drawing diagrams (modeling) that will be
transformed into code, scripting a web-based system, and choosing among several alternative
solutions.
Testing: XP model gives high importance to testing and considers it to be the primary factor to
develop fault-free software.
Listening: The developers need to carefully listen to the customers if they have to develop
good quality software. Sometimes programmers may not have the depth knowledge of the
system to be developed. So, the programmers should understand properly the functionality of
the system and they have to listen to the customers.
Name :TEJASWAROOP
Roll no : 21HQ1A0529
Subject : CICD
8
AVANTHI’S RESEARCH AND TECHNOLOGICALACADEMY
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
Designing: Without a proper design, a system implementation becomes too complex and very
difficult to understand the solution, thus making maintenance expensive. A good design results
elimination of complex dependencies within a system. So, effective use of suitable design is
emphasized.
Feedback: One of the most important aspects of the XP model is to gain feedback to understand
the exact customer needs. Frequent contact with the customer makes the development effective.
Simplicity: The main principle of the XP model is to develop a simple system that will work
efficiently in the present time, rather than trying to build something that would take time and
may never be used. It focuses on some specific features that are immediately needed, rather
than engaging time and effort on speculations of future requirements.
Pair Programming: XP encourages pair programming where two developers work together at
the same workstation. This approach helps in knowledge sharing, reduces errors andimproves
code quality.
Continuous Integration: In XP, developers integrate their code into a shared repository several
times a day. This helps to detect and resolve integration issues early on in the development
process.
Collective Code Ownership: In XP, there is no individual ownership of code. Instead, the
entire team is responsible for the codebase. This approach ensures that all team membershave
a sense of ownership and responsibility towards the code.
Planning Game: XP follows a planning game, where the customer and the development team
collaborate to prioritize and plan development tasks. This approach helps to ensure that the
team is working on the most important features and delivers value to the customer.
On-site Customer: XP requires an on-site customer who works closely with the development
team throughout the project. This approach helps to ensure that the customer’s needs are
understood and met, and also facilitates communication and feedback.
Name :TEJASWAROOP
Roll no : 21HQ1A0529
Subject : CICD
9
AVANTHI’S RESEARCH AND TECHNOLOGICALACADEMY
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
Misunderstanding the business and/or domain − Constant contact and explanations are
ensured by including the client on the team.
Costs incurred in changes − Extensive and continuing testing ensures that the modifications
do not impair the functioning of the system. A functioning system always guarantees that there
is enough time to accommodate changes without impairing ongoing operations.
Business changes − Changes are accepted at any moment since they are seen to be inevitable.
Production and post-delivery defects: Emphasis is on − the unit tests to find and repair bugs
as soon as possible.
Name :TEJASWAROOP
Roll no : 21HQ1A0529
Subject : CICD
10
AVANTHI’S RESEARCH AND TECHNOLOGICALACADEMY
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
Exercise-3
Devops adoption in projects
3. It is important to comprehend the need to automate the software development lifecycle stages
through DevOps. Gain an understanding of the capabilities required to implement DevOps,
continuous integration and continuous delivery practices.
DevOps Lifecycle
The DevOps lifecycle optimizes development processes from start to end and engages the
organization in continuous development, resulting in faster delivery times. This process mainly
consists of the following seven stages.
Subject : CICD
11
AVANTHI’S RESEARCH AND TECHNOLOGICALACADEMY
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
Continuous Integration
Continuous Integration (CI) is a DevOps software development practice that enables the
developers to merge their code changes in the central repository. That way, automated builds
and tests can be run. The amendments by the developers are validated by creating a built and
running an automated test against them.
Continuous delivery
Continuous Delivery (CD) is a DevOps practice that refers to the building, testing, and
delivering improvements to the software code. The phase is referred to as the extension of the
Continuous Integration phase to make sure that new changes can be released to the customers
quickly in a substantial manner. Continuous Delivery gives you the power to decide whether
to make the releases daily, weekly, or whenever the business requires it. The maximum benefits
of Continuous Delivery can only be yielded if they release small batches, which are easy to
Continuous deployment
When the step of Continuous Delivery is extended, it results in the phase of Continuous
Deployment. Continuous Deployment (CD) is the final stage in the pipeline that refers to the
automatic releasing of any developer changes from the repository to the production.
Continuous Deployment ensures that any change that passes through the stages of production
is released to the end-users. There is absolutely no way other than any failure in the test that
may stop the deployment of new changes to the output. This step is a great way to speed up the
feedback loop with customers and is free from human intervention.
Continuous testing
Next in the DevOps lifecycle is the testing phase, wherein the developed code is tested for bugs
and errors that may have made their way into the code. This is where quality analysis (QA)
plays a major role in checking the usability of the developed software. Successful completion
of the QA process is crucial in determining whether the software meets the client’s
specifications .Automation tools, such as JUnit, Selenium, and TestNG, are used for continuous
testing, enabling the QA team to analyze multiple code-bases simultaneously. Doing this
ensures that there are no flaws in the functionality of the developed software.
Continuous monitoring
Monitoring the performance of a software product is essential to determine the overall efficacy
of the product output. This phase processes important information about the developed app.
Through continuous monitoring, developers can identify general patterns and gray areas inthe
app where more effort is required.Continuous monitoring is an operational phase where the
objective is to enhance the overall efficiency of the software application. Moreover, it monitors
the performance of the app as well. Therefore, it is one of the most crucial phases of the DevOps
lifecycle.
Continuous feedback
Continuous feedback is essential to ascertain and analyze the final outcome of the application.
It sets the tone for improving the current version and releasing a new version based on
stakeholder feedback. The overall process of app development can only be improved by
analyzing the results from the software operations. Feedback is nothing but information
gathered from the client’s end. Here, information is significant, as it carries all the data about
the performance of the software and its related issues. It also contains suggestions given by end
users of the software.
Continuous operations
The last stage in the DevOps lifecycle is the shortest and easiest to grasp. Continuity is at the
heart of all DevOps operations that helps automate release processes, allows developers to
detect issues quickly, and build better versions of software products. Continuation is key to
eliminate diversions and other extra steps that hinder development.Development cycles in
continuous operations are shorter, allowing organizations to advertise constantly and accelerate
the overall time to market the product. DevOps enhances the value of software products by
making them better and more efficient, thereby attracting new customers towards it.
Exercise-4
Implementation of CICD with Java and open source stack
4. Configure the web application and Version control using Git using Git commands and version
control operations.
Aim: Configure the web application and Version control using Git using Git commands and version control
operations.
Git is a version control system which lets we track changes we make to wer files over time.
With Git, we can revert to various states of wer files (like a time traveling machine). we can
also make a copy of our file, make changes to that copy, and then merge these changes to the
original copy. With Git, we can create an identical copy of that file and play around with the
navigation bar. Then, when we are satisfied with wer changes, we can merge the copy to the
original file. we are not limited to using Git just for source code files – we can also use it to
keep track of text files or even images. This means that Git is not just for developers – anyone
can find it helpful.
I will assume that at this point we have installed Git. To verify this, we can run this command
on the command line: git --version. This shows we the current version installed on we PC. The
next thing we'll need to do is to set wer username and email address. Git will use this
information to identify who made specific changes to files.
git init
We are finally done with installing and setting up Git. It is now time to create our project. I
have created a folder on my desktop called Git and GitHub tutorial. Using the command line,
navigate to wer new project's location. For me, I would run the following commands:
git clone
git add
This command is used to add files to the staging.
git status
git reset
This command is used to unstage a file from the staging area. • Usage: Unstage the files form
staging area while keeping the file changes. git reset • Usage: Reset a commit. git reset [commit
id
git log:This command is used for listing the version history of the current git branch. • Usage:
For listing the version history of the current branch:
git show :
This command is used to view the metadata and the file changes of a specific commit. Checking
the metadata and file changes of a commit:
git tag: This command is used to add a tag associated with a commit. Usage: Adding a tag to a
commit: git tag [commit id]
git branch: This command is used to create a branch from the current working directory. •
Usage: Creating a new branch
git checkout :This command is used for switching among different git branches. Checkout a git branch:
git checkout [branch name]
Create a new branch and switch into it: git checkout -b [branch name]
git remote: This command is used to connect the local git repository to the remote server.
•Usage: Connecting to the remote server: git remote add [variable name] [Remote Server Link]
git push :This command is used to send your staged changes to the remote repository. • Usage:
Commit the staged changes to the remote repository. git push [variable name] [remote repositry
name]
git pull: This command is used to get the changes in the remote repository and merge them to
the current working directory. • Usage: Pull changes from a remote repository: git pull [variable
git stash
This command is used to temporarily store all the changed files in the working directory.
• Usage: Save all the modified tracked files temporarily: git stash
• Usage: List all the stashes: git stash list
• Usage: Delete the latest stash:
git fsck This command is used to check the integrity of the Git file system and it also helps in
identifying the corrupted objects.
• Usage: Integrity check of git file system:
Exercise-5
Implementation of CICD with Java and open source stack
5. Configure a static code analyzer which will perform static analysis of the web application
code and identify the coding practices that are not appropriate. Configure the profiles and
dashboard of the static code analysis tool
AIM: static code analyzer which will perform static analysis of the web application code and
identify the coding practices that are not appropriate. Configure the profiles and dashboard of
the static code analysis tool
Procedure:
SONARQUBE INSTALLATION
WHAT IS A SONARQUBE?
SonarQube is an open source platform developed by SonarSource for continuous inspection of
code quality.
It is written in JAVA and supports 20+ programming languages.
FEATURES:
1. Not just tells what is wrong, also aids you to rectify via Quality Management tool.
2. Covers a greater stretch as far as definition of Quality is concerned (as proudly flaunt by its
developers
– Seven Axes of Quality), as compared to its competitors, whom major emphasis is on bugs &
complexity.
3. Its focus is not only just constraint to potential bugs or code conventions, but also extends
to span
coding standards, duplications, test coverage, unit testing, code complexity, API
documentation, architecture, comments, bugs along with providing details in a dashboard is
cherry on the top.
4. It provides metrics, tracking of which can help you to take right decision.
5. It provides various features to support Continuous Inspection practice, viz. Quality Gates,
Focus on leak, highlighting hotspots, branch analysis, analyze pull requests, visualizing the
history of project.
Step 1:
Download the sonarqube software from
“ https://www.sonarqube.org/successdownloadcommunity-edition”
Step 2:
Extract the Zip file to the specific location Step
srtep 3:
Now open command prompt and change the directory to sonarqube bin upto windows 64 bit
installer
Step 4: Now type the command “StartSonar.bat” and now the SonarQube server will be started
Step 5: Now opensonarqube web server in browser by opening the following link
“http://localhost:9000” The screen appear as follows:
Step 6: Initially login as admin and the password will also be admin.Later it asks for update
password.
Step 7: Now the SonarQbue dashboard will be opened .In dashboard click on create project
mannually.Then one screen will appear ,it asks for project name and project key so Specify
them.
Step 8: Then click on setup , select locally tab as shown in below figure.
Step 9: After clicking on locally block the screen appears as below and provide a token then
set expires days and click on “generate” key
Step 10: The project name,project key and secret key are generated and save it at specific
location for futher use.
Step 11: Click on continue ,then one screen will appear and select the options as given below.
The sonarqube installed successfully and the project with token also created.To view the result
we have to install sonarQube-Scanner
SonarScanner is a separate client type application that in connection with the SonarQube server
will run project
analysis and then send the results to the SonarQube server to process it. SonarScanner can
handle most
FEATURES:
It can provide information regarding:
duplicated code
coding standards
unit tests
code coverage
code complexity
comments
Procedure of Static Code Analysis: Now open the command prompt and change the directory
to sonarQube-scanner project folder and execute the command “sonar-scanner.bat”
The project code is successfully analysed and the result is shared to the SonarQube dashboard
Now open the static code analysis report in the SonarQube server dashboard.It will show the
parameters like
• No of bugs
• Vulnerabilities
• Code smell
• Duplicate lines and so on….
All these can be observed in the below figure
Exercise -6
6Q: Write a build script to build the application using a build automation tool like Maven.
Create a folder structure that will run the build script and invoke the various software
development build stages. This script should invoke the static analysis tool and unit test cases
and deploy the application to a web application server like Tomcat ?
Aim: To implement a build script to build the application using a build automation tool like
Maven. Create a folder structure that will run the build script and invoke the various software
development build stages. This script should invoke the static analysis tool and unit test cases
and deploy the application to a web application server like Tomcat
Procedure:
Exercise-7
7) Configure the Jenkins tool with the required paths, path variables, users and pipeline views?
Aim: To implement and Configure the Jenkins tool with the required paths, path variables,
users and pipeline views
Procedure:
What is Jenkins and why we use it?
Jenkins is an open-source automation tool written in Java with plugins built for Continuous
Integration
purposes. Jenkins is used to build and test your software projects continuously making it easier
for developers
to integrate changes to the project, and making it easier for users to obtain a fresh build. It also
allows you to continuously deliver your software by integrating with a large number oftesting
and deployment technologies.
Installation of Jenkins
Step1: create aws account
Step2:login to it
Step5:creation of jenkins
installing java
Manage Jenkins
To manage Jenkins, click on the ‘Manage Jenkins’ option from the left hand menu side. So one
can get the various configuration options for Jenkins by clicking the ‘Manage Jenkins’ option
from the left hand menu side. You will then be presented with the following screen −
System Information
This screen displays a list of all the current Java system properties and system environment
variables. Here one can check exactly what version of Java Jenkins is running in, what user it
is running under, and so forth. The following screenshot shows some of the name-value
information available in this section.
System Log
The System Log screen is a convenient way to view the Jenkins log files in real time. Again,
the main use of this screen is for troubleshooting.
Load Statistics
This pages displays graphical data on how busy the Jenkins instance is in terms of the number
of concurrent builds and the length of the build queue which gives an idea of how long your
builds need to wait before being executed. These statistics can give a good idea of whether
extra capacity or extra build nodes is required from an infrastructure perspective. Script
Console
This screen lets you run Groovy scripts on the server. It is useful for advanced troubleshooting
since it requires a strong knowledge of the internal Jenkins architecture.
Manage nodes
Jenkins is capable of handling parallel and distributed builds. In this screen, you can configure
how many builds you want. Jenkins runs simultaneously, and, if you are using distributed
builds, set up build nodes. A build node is another machine that Jenkins can use to execute its
builds.
Prepare for Shutdown
If there is a need to shut down Jenkins, or the server Jenkins is running on, it is best not to do
so when a build is being executed. To shut down Jenkins cleanly, you can use the Prepare for
Shutdown link, which preventsany new builds from being started. Eventually, when all of the
current builds have finished, one will be able to shut down Jenkins cleanly.
Exercise-8
8) Configure the Jenkins pipeline to call the build script jobs and configure to run it whenever
there is a change made to an application in the version control system. Make a change to the
background color of the landing page of the web application and check if the configured
pipeline runs ?
Aim: To Implement and configure the Jenkins pipeline to call the build script jobs and
configure to run it whenever there is a change made to an application in the version control
system. Make a change to the background color of the landing page of the web application and
check if the configured pipeline runs .
Procedure:
You can create pipelines automatically for all branches and execute pull requests with just one
JenkinsFile.
You can review your Jenkins code on the pipeline
You can audit your Jenkins pipeline
This is the singular source for your pipeline and can be modified by multiple users.
Step 1)
The settings for the plugin can be found under Manage Jenkins>
Manage Plugins.
Installing Build Pipeline plugin in Jenkins
If you have already installed the plugin, it is shown under the installed tab.
Step 2)
If you do not have the plugin previously installed
it shows up under the Available tab.Once you have successfully installed the build pipeline
plugin in your Jenkins, follow these steps to create your Jenkins pipeline:
Subject : CICD
50
AVANTHI’S RESEARCH AND TECHNOLOGICALACADEMY
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
Step 1) Click on the “+” button on the left-hand side of your Jenkins dashboard to create a
pipeline.
Step 2) You will be asked to give a name to the pipeline view. We shall call it “Guru99 Pipeline”
for the duration of this demo. Select Build a pipeline view under options Click ok.
Step 3) In the next page, you will be asked for some more details to configure your Jenkins
pipeline. Just accept the default settings, and make sure you choose the first job under the
settings.
Subject : CICD
51
AVANTHI’S RESEARCH AND TECHNOLOGICALACADEMY
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
Step 2:
Now, under Build Triggers, check the Build after other projects are b
Subject : CICD
52
AVANTHI’S RESEARCH AND TECHNOLOGICALACADEMY
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
The Role Strategy Plugin enable you to assign different roles and privileges to different
users. You will first need to install the plugin in your Jenkins mange
environment.Create/Add a User in Jenkins Below are the steps to create new user in
Jenkins:
If you haven’t installed Jenkins in your local server, go to the appropriate URL and access
yourdashboard by using your login credentials.
Step 2: Choose the optionYou will now see options to create and add user in Jenkins and
manage current users.
Step 3: Create a new UserUnder Manage Jenkins, Click Create UserEnter Jenkins add user
details like password, name, email etc. Click Create User
53
AVANTHI’S RESEARCH AND TECHNOLOGICALACADEMY
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
Step 4: User is createdYou will see on the dashboard that a new Jenkins create user as per the
details entered.
54
AVANTHI’S RESEARCH AND TECHNOLOGICALACADEMY
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
Exercise-9
9) Create a pipeline view of the Jenkins pipeline used in Exercise 8. Configure it with user
defined messages?
Aim: To implement create a pipeline view of the Jenkins pipeline used in Exercise 8. Configure
it with user defined messages.
Procedure:
Step1: Select a folder which need to be pushed to Github repository.
Step 2: Follow the following procedure to push the files in desired repository.
55
AVANTHI’S RESEARCH AND TECHNOLOGICALACADEMY
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
Step 3: Open Jenkins and create new job by clicking on ‘New Item’.
Step 4: Give a unique name to job. Select ‘Freestyle project’ and then click on ‘OK’.
Step 5: After clicking ‘OK’, we will be directed to next step where we need to select ‘Git’ and
give URL ofour repository.
56
AVANTHI’S RESEARCH AND TECHNOLOGICALACADEMY
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
Step 6: Set Branch Specifier as ‘*/master’ if we have our file in it(of our mentioned repository).
With respect to the repository mention either ‘master’ or main.
If your codes are present in ‘master’ of Github then set master, otherwise ‘main’.
57
AVANTHI’S RESEARCH AND TECHNOLOGICALACADEMY
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
Step 8: Select ‘Java_file’ (our newly created job) and click on ‘Build Now’.
58
AVANTHI’S RESEARCH AND TECHNOLOGICALACADEMY
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
59
AVANTHI’S RESEARCH AND TECHNOLOGICALACADEMY
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
Exercise-10
10) In the configured Jenkins pipeline created in Exercise 8 and 9, implement quality gates
for static analysis of code?
STEP 1:
The sonarQube and sonarscanner has to be installed in your systems
STEP 2:
Open jenkins localhost Install the Jenkins Extension for SonarQube via the Jenkins Update Center.
STEP 3:
Configure your SonarQube server:
Log into Jenkins as an administrator and go to Manage Jenkins > Configure System
STEP 4:
Scroll down to the SonarQube configuration section, click Add SonarQube, and add the values
you're prompted for.enter the name(Any name) , provide localhost where sonarqube is running
STEP 5:
Global Configuration
This step is mandatory if you want to trigger any of your SonarQube analyses with the
SonarScanner. You can define as many scanner instances as you wish. Then for each
Jenkins job, you will be able to choose which launcher to use to run the SonarQube
analysis.
60
AVANTHI’S RESEARCH AND TECHNOLOGICALACADEMY
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
Log into Jenkins as an administrator and go to Manage Jenkins > Global Tool Configuration
Scroll down to the SonarScanner configuration section and click on Add SonarScanner. It is
based on the typical Jenkins tool auto-installation. You can either choose to point to an already
installed version of SonarScanner (uncheck 'Install automatically') or tell Jenkins to grab the
installer from a remote location (check 'Install automatically')
STEP 6:
Log into Jenkins as an administrator and go to Manage Jenkins>manage plugin and
installsonarQube scanner
STEP 7:
Create a PIPELINE JOB injenkins and move to pipeline option and select “pipeline script
from SCM”and provide github code link in Repository URL and credentials of your github
account
61
AVANTHI’S RESEARCH AND TECHNOLOGICALACADEMY
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
STEP 9:
Click on Build Now option and the job done successfully
62
AVANTHI’S RESEARCH AND TECHNOLOGICALACADEMY
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
Exercise-11
11) In the configured Jenkins pipeline created in Exercise 8 and 9, implement quality
gates for static unit testing?
63
AVANTHI’S RESEARCH AND TECHNOLOGICALACADEMY
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
option
the Configure
Step 2 − Browse to the section to Add a Build step and choose the option to Invoke Ant.
64
AVANTHI’S RESEARCH AND TECHNOLOGICALACADEMY
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
Step 4 − In the build file section, enter the location of the build.xml file.
65
AVANTHI’S RESEARCH AND TECHNOLOGICALACADEMY
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
Step 5 − Next click the option to Add post-build option and choose the option of “Publish Junit
test result report
Step 6 − In the Test reports XML’s, enter the location as shown below. Ensure that Reports is
a folder which is created in the HelloWorld project workspace. The “*.xml” basically tells
Jenkins to pick up the result xml files which are produced by the running of the Junit test cases.
These xml files which then be converted into reports which can be viewed later.
66
AVANTHI’S RESEARCH AND TECHNOLOGICALACADEMY
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
Step 7 − Once saved, you can click on the Build Now option.
Once the build is completed, a status of the build will show if the build was successful or not.
In the Build output information, you will now notice an additional section called Test Result.
In our case, we entered a negative Test case so that the result would fail just as an example.
One can go to the Console output to see further information. But what’s more interesting is that
if you click on Test Result, you will now see a drill down of the Test results.
67
AVANTHI’S RESEARCH AND TECHNOLOGICALACADEMY
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
68
AVANTHI’S RESEARCH AND TECHNOLOGICALACADEMY
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
Exercise-12
Q: In the configured Jenkins pipeline created in Exercise 8 and 9, implement quality gates for
code coverage?
Aim: To implement In the configured Jenkins pipeline created in Exercise 8 and 9, implement
quality gates for code coverage
Procedure :
Let’s setup Quality Gates metrics in Sonar. We are going to create a quality gate only for the
metric called Code Coverage for demo purpose. But there are more metrics available that you
should be selecting while creating quality gates.
Login to sonar > got Quality Gates as shown in the screen below.
Click on create > Add Condition > Choose metrics (In this example, we selected Code
Coverage) > select operator along with warning and error threshold.
69
AVANTHI’S RESEARCH AND TECHNOLOGICALACADEMY
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
Select the project to add Quality Gates. We have selected a sample miqp project. In your case,
project name would be different so please change it accordingly.
Now go to the Jenkins job and configure the Quality Gate validation.
Click on the job and go to Post-build Actions and provide the project details you have
associated with Quality Gate created in the earlier steps.
70
AVANTHI’S RESEARCH AND TECHNOLOGICALACADEMY
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
71
AVANTHI’S RESEARCH AND TECHNOLOGICALACADEMY
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
In the above screenshot, you can verify that the project miqp is reporting WARNING as the
code failed to meet the code coverage metric (i.e we set in one of the earlier steps).
Conclusion
In this article, we have shown how you can take your code analysis benefits to the next level
using Quality Gates. We also walked you through the process of setting up Quality Gates at
build level, using sonarqube and Jenkins.
This definitely helped the teams at MiQ by being on top of our quality control check and that
too in automated fashion. We are sure that this process can help you in your development
process as well.
72