0% found this document useful (0 votes)
27 views87 pages

DEVOPS

Uploaded by

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

DEVOPS

Uploaded by

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

lOMoAR cPSD| 42578591

III Year – I Semester


CONTINUOUS INTEGRATION AND CONTINUOUS DELIVERY USING DevOps
(Skill Oriented Course)
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING
List of Exercises:

Note: There are online courses indicated in the reference links section. Learners need to go
through the contents in order to perform the given exercises

Exercise 1:
Reference course name :Software engineering and Agile software development
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.
Solve the questions given in the reference course name to gauge your understanding of the topic

Exercise 2:
Reference course name: Development & Testing with Agile: Extreme Programming
Get a working knowledge of using extreme automation through XP programming practices of test first
development, refactoring and automating test case writing.
Solve the questions in the “Take test” module given in the reference course name to gauge your
understanding of the topic

Exercise 3:
Module name : DevOps adoption in projects
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.
Solve the questions given in Quiz1, Quiz2, Quiz 3

Exercise 4:
Module name :Implementation of CICD with Java and open source stack
Configure the web application and Version control using Git using Git commands and version control
operations.

Exercise 5:
Module Name: Implementation of CICD with Java and open source stack
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.

1
lOMoAR cPSD| 42578591

Exercise 6:
Module Name: Implementation of CICD with Java and open source stack
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.

Exercise 7:
Module Name: Implementation of CICD with Java and open source stack
Configure the Jenkins tool with the required paths, path variables, users and pipeline views.

Exercise 8:
Module name: Implementation of CICD with Java and open source stack
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.

Exercise 9:
Module name: Implementation of CICD with Java and open source stack
Create a pipeline view of the Jenkins pipeline used in Exercise 8. Configure it with user
defined messages.

Exercise 10 :
Module name: Implementation of CICD with Java and open source stack
In the configured Jenkins pipeline created in Exercise 8 and 9, implement quality gates for
static analysis of code.

Exercise 11:
Module name :Implementation of CICD with Java and open source stack
In the configured Jenkins pipeline created in Exercise 8 and 9, implement quality gates
for static unit testing.

Exercise 12:
Module name :Course end assessment
In the configured Jenkins pipeline created in Exercise 8 and 9, implement quality gates for code coverag e.
lOMoAR cPSD| 42578591

Exercise 1
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 Engineering:

Need of software engineering: -


1. Vision of the project and outcomes
2. Clarity on requirements
3. Analysis and design
4. Development
5. Testing
6. Deployment and maintenance.

SoftwareEngineering

Concept: - Software Crisis:

1. Time and cost slippage

2. Failure at customer’s site

3. Untraceable errors after delivery

4. Difficulty in maintenance

5. Information leak when multiple stakeholders at play.


Definition: -
It is the application of a systematic, disciplined, quantifiable approach to the
development, operation maintenance of software i.e., the application of engineering to
software.

Life cycle: -

1. Requirements: -capture requirements from stake holders

2.Design: -Arrive at the high-level design of software

3.Coding: -Translate design to code

4. Testing: -Validate requirements against code developed

5.Deployment: -Deploy software in customer environment

6.Maintenance: -Support customer on post-production issues


lOMoAR cPSD| 42578591

Models: -

A conceptual framework which describes activities in a project end-to-end

1.Waterfall

2.Prototyping

3.Spiral

4.Rapid application Development

Project Roles: -

1. Project Sponsor

2. Business Team

3. Developers

4. Tester

5. Support Team

6. Designer

7. Architect

8. Project Manager

Agile software Development:

Why Agile:

1. Responding to changes quickly with quality

2. Quick time to market


3. Develop software amidst requirements volatility

Benefits:

1. Faster time to market

2. Quality software

3. Adopt to changes quickly

4. Sustainable development admits uncertainty


lOMoAR cPSD| 42578591

Principles:

1. Our highest priority is to satisfy the customer through early and continuous delivery
of valuable software.

2. Welcome changing requirements, even late in development. Agile process harness


change for the customer’s competitive advantage.

3. Delivery working software frequently, from a couple of weeks to a couple of


months, with a preference to the shorter time scale.

4. Businesspeople and developers must work together daily throughout the project.

5. The most efficient and effective method of conveying information to and within a
development team is face-to-face conversation.

6. Build project around motivated individuals give the environment and support they
need and trust them to get the job done.

7. Working software is the primary measure of progress.

8. Agile processes promote sustainable development. The sponsors, developers and


users should be able to maintain a constant pace indefinitely.

9. Continuous attention to the technical excellence and good design enhances agility.

10.The best architecture, requirements and design emerge from self- organizing teams.

11. At regular intervals, the team reflects on how to become more effective, then tunes
and adjusts its behavior accordingly’

12. Simplicty—the art of maximizing the amount of the work not done-is essential.
lOMoAR cPSD| 42578591

Exercise 2

Aim: Exploring the working knowledge of using extreme automation through XP


programming practices of test first development, refactoring and automating test case
writing.

Procedure:
Extreme Programming:

Get a working knowledge of using extreme automation through XP Programming


practices of test first development, refactoring and automating test case writing.

Extreme Programming (XP):

Will use Git which is a source control tool to be using in Extreme Programming. It
provides 12 practices such as code refactoring continuous Integration etc.

Methodology to integrate Agile into Software Development for an Efficient and


Dynamic team.

Extreme Programming Concepts:

1. Quality Improvements
2. Process Improvement
3. Customer Satisfaction Improvements

Advantages:

1. Focuses on Key activities


2. Cost and time efficiencies
3. Reduces risks
4. Uncomplicated
5. Transparency
6. Ongoing feedback
7. Focuses on customer needs
8. Equal Accountability

Roles:

1. Customer: Asks for his requirements


2. Tracker: Checks whether the task is going on properly
3. Developer: Understand customer requirements and start coding
4. Coach: Guides the development team and customer to go in a proper
way
lOMoAR cPSD| 42578591

5. Communication: Communicating with customer properly


6. Simplicity: Easy to understand

7. Feedback
Practices:
8. Courage: Discuss about a project to the company head

9. Respect

● Whole team
● Sir together
● Informative workspace
● Energized work
● Pair Programming
● Stories
● Weekly and quarterly cycles
● Slack
● Ten-minute build

Extreme Programming use case:

● All activities performed throughout the development


● Iteratively builds
● Resilience
● Enable changes

Planning:

● Plan
● Design
● Code
● Test

Feedback:

● Customer acceptance tests


● Project Manager

Planning Game Practices:

● Organized meeting
● Ensures quality improves design
● Promotes effective project management
● Two parts-release planning and iteration planning
lOMoAR cPSD| 42578591

Release Planning:

● Customer
● Software developer

Release Planning -Exploration Phase:

● What software
● How it works

Planning -Commitment phases:

1. Functionality
2. Release date

Game parts and phases

● PLANNING GAME
1. Release Planning
2. Iteration Planning
1. Release Planning
1. Exploration
2. Commitment
3. Steering

2.Iteration

Planning

1. Exploration
2. Commitment
3. Steering

Planning -Steering phase

● Adding
● Reviewing
● Revising

Iteration Planning Exploration:

● Refine user story card requirements


● Translate requirements into tasks
● Create task cards

Iterative planning -Commitment phase:

● Assign tasks
lOMoAR cPSD| 42578591

● Determine duration
lOMoAR cPSD| 42578591

Iteration Planning-Steering phase:

● Complete tasks
● Validate design
● Evaluate design
● Adjust

Pair Programming

● Two programmers
● Shared workstation
● Regular role switching

Benefits

● Increase quality of code


● Grows collective team knowledge
● Enables skills transfer to more experienced development
● Reduce coordination efforts
● Improves coding resiliency

Skills level:

● Beginner
● Intermediate
● Advanced

Disadvantages:

● Requires active engagement by both participant


● Potential cost increase
● Requires good communication
● Requires good relationship between the participants

Code Check Options:

● Pair Programming
1. Instant and regular code review
2. Require both programmers
3. Shared Understanding
4. Real-time correction
5. Reduces risks
● Code Reviews
1. Separate programmer looks at code at a later time
2. Testing, quality, control
lOMoAR cPSD| 42578591

3. Limited understanding after act

Effective of Pair Programming

● Can be advantageous if used correctly


● Requires understanding different styles and how they each work
● Different scenarios require different styles of Pair Programming
● Six common styles of Pair Programming

Back-Seat Navigation:

● Tactical focus
● Both tactical and strategic

Ping -Pong Pairing:

● One developer purposely writes a falling test


● Second developer focuses on getting it pass
● Then roles switch

Test Driven Development Benefits:

● Design
● Coding
● Testing

Test Driven Development Benefits:

● Helps you build every buy notification capability


● Increased design efficiency
● Provides refactor confidence
● Enables collaboration
● Reduces debugging and development time

Levels:

● Acceptance Test Driven Development


● Developer Test Driven Development

Comparing Testing Approaches:

● Ensures confirmatory -level testing


● Verifies system meets defined requirements
● Focuses on production code to verify testing
● Tests every lines of code
lOMoAR cPSD| 42578591

● Traditional Testing
● Focuses on test case design

Considerations:

● Not fool proof


● Requires full team collaboration
● Slower process

Source Control Management (SCM) and Tools:

● Tracking and managing


● Ensuring version control

Benefits:
● Maintains single source
● Facilities collaboration
● Accelerates velocity

SCM Best practices:

● Select the most appropriate system for your needs


● Store your code directly in the system
● Always pull latest versions of code
● Ensures you commit code often, including details
● Make use of branches for parallel work

SCM Tools:

● GIT - Set of Commands

-Git hub repository

● Perforce Metrix core


● Sub Version
● Clear cases
● Team foundation server
● Mercurial

Git Hub Steps:

1. Open browser https://GitHub.com


2. Creates repository of repository name is your name
3. A repository with a name xxxxx will be created. Now, In this repository it have
one file readme mid.. Readme files lists and all the fields in current directory
lOMoAR cPSD| 42578591

4. In GitHub main branch will be the root branch. To this branch, anyno.of sub
branches can be created.
5. Let's create a new application code and save it in repository

(i) Clone to repository on the local machine

(ii) Now download GitHub desktop

(iii) Open GitHub desktop and click on clone repository from the internet

(iv) It asks which repository is to be cloned and select the repository and then
click on "Clone".

Continuous Integration:

● Prevent code overlap


● Remote Integration issues

Benefits:
● Rapid time to market
● Faster development life cycles
● Increased quality
● Better risk mitigation

Risks :
● Costs for maintaining and managing
● Requires established guidance before use
● Lack of experience
● Requires full test coverage
● May mid guide team focus

Benefits:
● Requires commit code
● Categorize developer tests
● Use a dedicated machine
● Integrate continuous feedback
● Stage your build

Continuous Integration in Actions :


lOMoAR cPSD| 42578591

Coding standard practice and Benefits

Coding Standards

● Consistency
● Manageability

Coding standards benefits:

● Reduced rates of failures


● Development time optimization
● Simplified debugging
● Cost controls

Coding standard categories:

● Mandatory
● Guidelines
● Recommendations

Coding standard Elements:

● Format
● Code structure
● Naming conventions
● Error Handling
● Comments

Coding standard Best Practices:

● Understand the purpose


● Consider your industry
● Comply with rules and follow recommendations
● Describe intent
● Update carefully
lOMoAR cPSD| 42578591

● Consider open vs. closed


● Prioritize rules
● Plan for deviations

Collective code Ownership:

● Team produces quality product


● Every team member equality responsible

Knowledge Sharing:

● Eliminate critical knowledge silos


● Promotes collective learning

Code Excellence:

● Increased quality
● Style efficiency

Remove dependencies on Individuals:

● Eliminates the risk of the lottery "effect"


● Promotes collective responsibilities

Efficient code Reviews:

One knows truly knows solution

Greater learning Scope:

● Continuous learning
● Shorter learning time

Collective code Ownership Disadvantages:

● No Individual Ownership
● Relies on team expertise
● May hinder motivation
● Not suited for Specialized functions

Code Refactoring:

● Editing without changes to function


● Code efficiency
● Prevent bugs in future
lOMoAR cPSD| 42578591

● Avoid code rot

Refactoring Benefits:

● Maintainability
● Extensibility

Refactoring Techniques:

● Red/green
● Refactoring by abstraction
● Composing method
● Simplifying method
● Preparatory
● Moving features between objects

Refactoring process:

● Identify
● Conduct
● Test
● Repeat

Refactoring Best Practices:

● Decouple (test you know)


● Consider infrastructure
● Plan

Refactoring in Agile Software Development

● Improves software consistency


● Helps fix bad code
● Increases time efficiencies
● Increases Simplicity
● Evolves iteratively

The problems

● Older code with duplication


● Updates by many developers over years
● Multiple variations for similar products
● Difficult to understand
● Starting to experience unintended side effects with new updates
lOMoAR cPSD| 42578591

Restructuring:
● Reduce duplication
● Resize classes and methods

Addressing Duplication:

● Extract
● Replace
Simplifying

● Adding new code in the future


● Replacing code later

Small Releases:

● Deliver value fast


● Quick feedback
● Quick wins for team
● Reduces risks
● Build adaptability

Prepare

● How iteration occur


● Time intervals

Meet & Discuss

● Evaluate
● Identify team goals and strategies
Iteration Details

● Value to customer
● Maximum two weeks between iterations
● Quality

Apply Lessons Learned

● Incorporate feedback
● Experiment
● Add new features

System Metaphor

Changing standard project architecture names to easily understood non -technical


terms of phrases
lOMoAR cPSD| 42578591

System Metaphor Goals

● Common vision
● Generativity
● Shared vocabulary
● Architecture

Advantages

● Enables easier system understanding


● Enables model comprehension
● Expands range

Disadvantages:

● May break cultural protocols


● May make users avoid systems
● May create conflict
● May lead to using bad designs

Best Practices:

● Single view
● One structure type
● Clear design guidance
● System properties focus
● Shared experience

Applying the 40 - hour work week

● The practice of not requiring programmers or software developers to


work more than 40 hours per week or work overtime two weeks in a
row

Key Concepts

● Team members work best when we'll - rested


● Requires frequent code merging
● Quality code is required
● Frequent code development minimizes risk

Benefits

● Creative thinking time


● Time for quality
● Cross - training
lOMoAR cPSD| 42578591

● Problem exposure

Considerations

● Development
● Quality
● Delivery
● Improvement

Determining sustainable pace

● Experiment
● Increase slowly
● Track

Course Summary

● Extreme Programming
● Planning Game Practices
● Pair Programming
● Test - Driven Development
● Customer Role practice
● Source Control Management and Coding standard
● Continuous Code Ownership and Code Refactoring
● Small Releases and System Metaphor
● The 40 - hour work week
lOMoAR cPSD| 42578591

Exercise 3:
Aim: 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.
Procedure:
Dev-ops Adoption in Projects:
It is the important to comprehend the need to automate the software development
lifecycle stages through Devops, gain an understanding of the capabilities required to
implement Devops, CI, and CD
Devops:
It is the combination of development team and operational team.
• Version source code
• Code quality analysis
• Unit testing
• Code coverage
• Create executable
• Baseline the executable

These activities are done in continuous integration of pipeline.


Test and test data management automation:
• Functionality test
• Test and test data management
• Performance test
• Security test

They are the different test done by development and delivery pipeline.
Continuous delivery and automation:
CD allows constant flow of changes into production through automated software
production pipeline called CD pipeline.
Infrastructure layer and environment management:
This provides required infrastructure for development.
This infrastructure can be managed by tool called as chef.
Chef: helps in spinning of virtual machine synchronized them and made changes
across multiple servers.

Operations team:
lOMoAR cPSD| 42578591

Operational team contains 2 types of dash boards to measure devops adoption and
health of pipeline.
1. Business performance dashboard
➢ Depict the revenue and speed of deployment defect status.

2. End user dashboard


➢ Provide code as well as API to executable.

Tools stack and its implementation:


1. Continuous integration and activities involved.

Tools:Continuous integration lifecycle stage:


➢ Version control: Git

It is an open-source tool which is free of cost, eclipsed IDE also open-source tool
which contain e-git plug-in.
➢ Static code analysis: SonarQube

It is an Open source, free and powerful tool.


➢ Unit test: unit

As it is integrated with the eclipse IDE


➢ Build automation: Maven
lOMoAR cPSD| 42578591

Very powerful, integrated with eclipse IDE used for coding and helps write
Compact scripts. It is compactable with the tools mentioned.
➢ Artifact repository: artifact repository supports Maven free and open source.
➢ Continuous Integration: Jenkins free, open source, powerful and
➢ integrates with all the tools mentioned.
lOMoAR cPSD| 42578591

Exercise 4
Aim: Configure the web application and Version control using Git using Git
commands and version control operations.
Tools Required: Git, Github cloud account, Internet connection, browser, Github
Desktop(optional).
Theory:
Github: GitHub is a website and cloud-based service that helps developers store and
manage their code, as well as track and control changes to their code.
Procedure:
Step-1: Open your browser and search for github and click on link: https://github.com/
Step-2: Now sign with your existing GitHub credentials or sign up for a new GitHub
account.
Step-3: After sign-in click on new to create a new repository. Add your name to your
repository and check on add a readme file and click on create repository. It creates a
new repository.
Step-4: And then install Git in your Pc by using the link: https://www.git-scm.com/
And then after installation complete open the Git-bash.
Type these commands:

Step-5: After login with your credentials and type these commands to commit the file.
Step-6: Now push the file to cloud repository. So we use the command.
lOMoAR cPSD| 42578591

Step-7: Now open the github cloud and click on compare and pull request and then all
files are stored in master branch.

Step-8: Now create a new branch and again step those files in that branch.
The commands are:
lOMoAR cPSD| 42578591

Now we pushed the files into the new branch named branch1.
Let check it at github cloub whether the branch is created and files are pushed or not.
lOMoAR cPSD| 42578591

The branch is created and the file is also pushed.

Step-9: Now we clone the files into a one new directory(i.e in Local repository) from
github cloud repository
The commands are:
lOMoAR cPSD| 42578591

After cloning the files check the files whether they are opening or not.

Conclusion:
We learned how to use the github cloud and their git commands to push the files to
cloud repository, creating a new branch, and cloning the files from github cloud to
local repository.
lOMoAR cPSD| 42578591

Exercise 5
Aim: Configure a static code analyzer which will perform static analysis of the web
application code.
Tools Required: SonarQube 7.9.6 LTS, Java 11, Sonar Scanner 4.7, Eclipse IDE,
Internet Connection.
Theory:
Static Code Analysis: Analysing the code without executing is called static code
analysis.
• For performing static code analysis we are using SonarQube which is a web
page open source tool to manage code quality.
SonarQube: SonarQube checks the code whether the comments, coding rules are
followed correctly and properly or not.
• Checks for code complexity.
• Checks for duplication in code.
• It covers only the C, C++, Java Languages only.
• It has a list of built-in rules for different programming languages and these
rules are called Profiles.
Procedure:
Step-1: Go to any search engine and type Download SonarQube 7.9.6 or go to this
link: https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-7.9.6.zip
lOMoAR cPSD| 42578591

Step-2: After completion of downloading extract into a specified folder. And open the
extracted SonarQube 7.9.6 folder and click on bin and copy the path of folder upto
BIN.
in my case: E:\sonarqube-7.9.6\bin)
Step-3: Go to Settings (for Windows 10 or Windows 11) and click on System and go
to about -click on Advanced System Settings and click on Environment variables and
on system variables go and edit the path and add new path by clicking New and paste
the path of SonarQube extracted folder.

Step-4: Download Eclipse IDE from Official website:


https://www.eclipse.org/downloads/
And install the Eclipse IDE for Java Developers.
lOMoAR cPSD| 42578591

Step-5: After installing open the Eclipse IDE and click on File and click New to create
the Java Project.
Give the project name and details of project and click on finish.

Step-6: After creating the java project and then right click on your project folder and
click on new to create a Class file.
lOMoAR cPSD| 42578591

Give the details of class and click on finish.

In Src folder contains the main class file and write your code on that file and save it.
lOMoAR cPSD| 42578591

Step-7: Right click on SonarProj1 (or your project name) and click on properties and
copy the path of your project workspace.
And then again open the browser and search for SonarScanner 4.7 and download it.
And extract the folder at one place (or you can extract the file where you have extract
SonarQube file). And copy the path of your SonarScanner folder upto Bin folder.
lOMoAR cPSD| 42578591

Step-8: And again open the Sonar-Scanner folder after that click on conf folder and
then edit the “ sonar-scanner ” file in either notepad or VS code.
Add these contents to that file without deleting any contents in that file.

For my project my credentials will be added as:


lOMoAR cPSD| 42578591

Step-9: To run the Sonar-Scanner open the command prompt and change the directory
of SonarQube upto bin/windows-x86-64/

Step-10: From here onwards we must run the SonarQube-7.9.6 on Jdk 11 (or) Java
SE 11. So uninstall and delete the path in environment variables of higher version or
lower versions of java.
Java SE 11: https://www.oracle.com/in/java/technologies/javase/jdk11-archive-
downloads.html#license-lightbox
lOMoAR cPSD| 42578591

And after installation of Java SE 11 then set up path of java in Environment variables.
And then type in command prompt where the path is at SonarQube up-to windows-
x86-64 then type this command:
>StartSonar.bat

Step-11: After getting the script like Process[ce] is up and SonarQube is up and
then open your browser and type this URL: http://localhost:9000
• Where this URL was found in SonarScanner folder->conf folder->sonar-
scanner file.
lOMoAR cPSD| 42578591

• In that file it contains “sonar.host.url” where the URL was default to that file
where we can change when we want in that file.

Step-12: And now open the another command prompt window and then change the
directory to your project workspace which is located at eclipse workspace directory.
My project workspace can be seen at eclipse also i.e :

And then change the directory to project directory in command prompt:


lOMoAR cPSD| 42578591

And then type this command in command prompt: sonar-scanner.bat

Wait for till it gets EXECUTION SUCCESS.


lOMoAR cPSD| 42578591

Step-13: Now open your browser which is previously that we opened that
SonarQube server, refresh it and then see the projects and click on the project to see
the status of project.

Step-14: As that I was highlighted in a box click on 1 of projects analyzed to see the
status. And click on your project name to see the full status as given below.
lOMoAR cPSD| 42578591

Step-15: If there is any errors are occurred in project then it displays as like:
I have created another project named sonarProj2 and I created a class with named
smileyProj2 with some errors.
And I am following above same process upto opening of SonarQube. Now I am
configuring the sonar-scanner.properties file with the details of project:

And I executed with sonar-scanner at sonarProj2 project directory and then now
check at SonarQube whether it raises any errors or not:
lOMoAR cPSD| 42578591

And now open the SonarQube server webpage to see the project is added or not:

Yes the another was successfully added. Click on 2 to open the projects.
lOMoAR cPSD| 42578591

Click on issues to check what issues are raised.

In the below photo it shows us issues and errors in the following code.
lOMoAR cPSD| 42578591

Conclusion:
We concluded that we had learn on how to do the static code analysis with SonarQube
and with sonar scanner.
lOMoAR cPSD| 42578591

Exercise 6:
Aim: 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.
Tools: Eclipse IDE, Apache Maven(version: 3.8.6)
Theory:
Maven: A maven is a build tool that helps in project management. This tool helps in
building and documenting the project.
• Maven is a build automation tool written in Java and C# and this is based on
Project Object Model (POM).
• POM is fundamental unit in maven. It is an XML file which resides in the
base directory of our project.
• When we execute a maven project it searches for the POM in the current
working directory.
• POM contains:
1.Project Dependencies
2.Plugins
3.Build profiles
Maven build Lifecycles:
1. Clean: It cleans the target directory for to deploy the project.

2. Validate: It will checks whether the project is correct and by checking all the
necessary information.
3. Compile: Compile the source code of project.

4. Test: Test the compiled source code using a suitable unit testing framework.

5. Package: Take the compiled code and package it in its distributable format, such as
a JAR.
6. Install: Install the package into the local repository, for use as a dependency in other
projects locally.
7. Deploy: Done in the build environment, copies the final package to the
remote repository for sharing with other developers and projects.
Eclipse: Eclipse is an IDE(Integrated Development Environment) for developing
java projects.
lOMoAR cPSD| 42578591

Procedure:

Maven Installation:

➢ It is an open-source and which can be downloaded from website:


https://maven.apache.org/download.cgi
➢ Go to files in that link given above and check for the name Binary zip archive
and click on the link: apache-maven-3.8.6-bin.zip to download it.
➢ After downloading the zip file extract it in a specified directory path.
➢ Setting up Environment Variables (Windows 10 or 11):
o Go to Settings -> System and then goto About and then click on
Advanced System Settings
o And then it opens System properties and then click on Environment
variables-> go to System Variables -> under system variables click on
New and Give the variable name and path.

Variable Name: M2_HOME


Variable Value: E:\apache-maven-3.8.6 //(as per my drive is E)

o And click on ok and then go to variable Path -> and click on new under
path variable tab and and give the name as %M2_HOME%
o And paste another path of maven up to bin folder: E:\apache-maven-
3.8.6\bin
lOMoAR cPSD| 42578591

o And then Click ok-> ok -> ok.

➢ And then open command prompt to check if it correctly installed its path in
environment variables.
➢ Type the command in command prompt as ‘mvn -version’

➢ If it displays as above format then the Maven is successfully installed.


lOMoAR cPSD| 42578591

Deploying a Maven project:


Step-1: Open Eclipse IDE and click on File -> New -> Other -> Maven
Project ->Use default workspace location -> Next

Step-2: After clicking Next -> Select an archetype -> Filter it by :


“org.apache.maven.archetypes” and select it with maven-archetype-
quickstart as artifact id with version 1.4.
And give the group-id and and artifact id of project and click finish to
demonstrate the maven project in Eclipse IDE.
lOMoAR cPSD| 42578591

Step-3: Under MavenApplication we have 2 folders:


1. src/main/java: This folder contains all the java files require to run the project.
By default it contains a file named as App.java
2. src/test/java: This folder contains test files to test the java programs which
are there in src/main/java.
3. JRE System folder contains predefined libraries and packages to run the
java application.
4. Maven Dependencies: It contains required maven dependencies to run as
well as to test the app.
5. Target folder contains: 1.Class files 2.jar files

Step-4: To run the MavenApplication we must ensure with lifecycles:


Right click on Project Name (i.e: MavenApplication in my case) -> click on
option Run As -> click on Maven Clean where it run and shows as BUILD
SUCCESS
lOMoAR cPSD| 42578591

And then click 4th option in Run As i.e: Maven Build and give the goals as
validate to validate and click run
lOMoAR cPSD| 42578591

After that again click on 4th option in Run As i.e: Maven Build and give the
goals as compile to compile it and click run.
lOMoAR cPSD| 42578591

After completing 3 lifecycle methods with BUILD SUCCESS then click


Run As -> Maven Install -> And then it generates the .jar file in target folder.

Before the maven install lifecycle the target folder is empty where as by
lifecycle of install the target contains files of built project with “projectname-
0.0.1-SNAPSHOT.jar”
lOMoAR cPSD| 42578591

Step-5: To run the class file which is located at target folder named with classes
directory.
Paste the path upto classes directory in command prompt and click the
command to run the class file as
>java com.Mynewbee1.MavenApplication.App
lOMoAR cPSD| 42578591

The .jar file under the target folder after maven install is :

Conclusion:
After performing all maven build lifecycles it creates class file and jar
files in target folder of certain project.
lOMoAR cPSD| 42578591

Exercise 7
Aim: Configure the Jenkins tool with the required paths, path variables, users and
pipeline views.
Tools required: JDK-11, Jenkins 2.361.3 LTS
Theory:
Jenkins: Jenkins is an open source automation server. It helps automate the parts of
software development related to building, testing, and deploying, facilitating
continuous integration and continuous delivery.
• It is a server-based system that runs in servlet containers such as Apache
Tomcat.
Procedure:
Step-1: First go to website of Jenkins download :
https://www.jenkins.io/download/

Step-2: Download the Jenkins 2.361.x LTS of Generic Java Package with the
extension of .war file. Save that file in a particular directory for easy accessing
(in my case the filed is stored in E:drive).
Step-3: Java version will be JDK 11 only. Install the JDK 11 and remove higher
versions or lower versions of Java.
Step-4: Set the path of JDK 11 in Environment variables.
lOMoAR cPSD| 42578591

Step-5: Open the command prompt and make sure the path will be your Jenkins
file saved path.

Change the path to Jenkins file path and then click this command:
>java -jar Jenkins.war
Then it will extract its file into windows system and then it executes its
operation.

On first time using of jenkins it generates a random password which is stored at


c:\users\hp\.jenkins\secrets\initialAdminPassword path. Copy the password.
lOMoAR cPSD| 42578591

Step-6: Open your default browser and then the Address as:
http://localhost:8080
It will redirects to this page for first time using of Jenkins.

Paste the copied password from initialAdminPassword file


Step-7: After successfully entering the password it redirects to this page which
is shown below.

If you have good internet connectivity then install suggested plugins.


lOMoAR cPSD| 42578591

After then change your Admin password as admin and email is


admin@admin.com of Jenkins. And click start Jenkins.
Step-8: Then it opens the Jenkins home page.

Conclusion:
We learned how to install the Jenkins and its plugins.
lOMoAR cPSD| 42578591

Exercise 8
Aim: Create a Free style project in jenkins by integrating Maven Project and
executing the project in Jenkins IDE.
Tools Required: Jenkins LTS, Java with JDK 11, Apache maven.
Procedure:
Step-1: Open Jenkins tool in which we discussed in Exercise -7. And click on
New Item to create a new item with “freestyleproject” and give the name for
the project and then click Ok.
lOMoAR cPSD| 42578591

Step-2: After creating the item it redirects into another configuration menu. In
this configuration menu under General give your description and click apply.

Step-3:
Installation of Plugins or Dependencies:
For the installation of plug-ins, First go to homepage of Jenkins and go to
Dashboard and click Manage Jenkins and then click on Global Tool
Configuration under manage Jenkins.
lOMoAR cPSD| 42578591

Step-3.1: Adding the JDK in Global Tool Configuration by giving the


certain information of Java installed in your pc.
(in my case JDK 11 So)
JDK
NAME: JDK11
JAVA_HOME: C:\Program Files\Java\jdk-11.0.16.1

Step-3.2: Adding the Maven in Global Tool Configuration by giving the


certain information of Apache Maven installed in your pc.
Maven
Name: M2_HOME
MAVEN_HOME: E:\apache-maven-3.8.6

And then click on Apply and Save.


Step-4: After saving then go to Dashboard. At there select your Project (at my
case it is myNewJen1).
And then go to configure and click on go to build steps and add build step as
Invoke top-level Maven targets and then maven version will be select as
M2_HOME and under goals give clean install as a goal.
lOMoAR cPSD| 42578591

Step-5: On Build Steps by clicking on advanced button and Enter the POM path
under POM in which the path will be project of java:
C:\Users\chara\eclipse-workspace\MavenApplication\pom.xml
And then click on apply and Save it.

Step-6: On your project there are some options are at left side and click on
Build Now option to run the maven project on Jenkins.
lOMoAR cPSD| 42578591

Step-7: Click on console output to see the output screen.

Conclusion:
We finally conclude that we have learned how to create a freestyle project.
lOMoAR cPSD| 42578591

Exercise 9
Aim: Develop a jenkins application that will integrate with the code in Github.
Tools Required: Jenkins, Github desktop or Git-bash, Integrated Browser(Edge or
Chrome).
Theory:
Jenkins: Jenkins is an open-source automation server. It helps automate the
parts of software development related to building, testing, and deploying,
facilitating continuous integration and continuous delivery.
Procedure:
Step-1: Create a Hello world program in Python or Java language and save it on one
path (at my case I had used the python language).

Step-2: Open the Git-bash to push the file into github repository. Create a repository
named Jenkins-Git-Integration.
And then change the directory to where the python file is saved. And initialize the
repository to that directory.
lOMoAR cPSD| 42578591

And then apply the commands of git which will be discussed at exercise-4 for up-to
pushing a file to global repository.
Step-3: Open the Jenkins by typing java -jar Jenkins.war and then go to Jenkins
homepage and click on new item and named it as “Jenkins git integration” as a
freestyle project and click on Ok.

Step-4: To execute github project under Jenkins then go to Dashboard and click on
Manage Jenkins and click on Manage plugin.
lOMoAR cPSD| 42578591

Step-5: At available search for “git plugin” and click on Install without restart.
Again search for “GitHub integration” and click on Install without restart.
For git plugin:
lOMoAR cPSD| 42578591

For github integration:

Step-6: Go to the jenkins project and click on configure(Configuration) and click on


Source code management and click on Git. Copy the path of repository in Github
cloud.
lOMoAR cPSD| 42578591

Paste the repository URL path in Repository URL.

Step-7: Go to Build Triggers and check the Poll SCM and under Schedule input it
as * * * * *
It means that it has polls every minute.
lOMoAR cPSD| 42578591

Go to Build steps and select under Build steps as Execute windows Batch Command
Under Command, type your command to compile and execute the program. For each
programming languages there is a difference command to run the code.
For Java:
javac program_name.java
java program_name
For python:
python program_name.py
lOMoAR cPSD| 42578591

And click on apply and save.


Step-8: it directly redirects to your project there it contains some options, click on the
Build Now option to execute its process.

And check the output of project code by right clicking it displays some options and
click on console output to display its brief output.
lOMoAR cPSD| 42578591

Conclusion:
we finally conclude that we had learned how to integrate the Jenkins and github and
how to build and test our software projects continuously making it easier for us to
integrate changes to the project, and making it easier to obtain a fresh build.
lOMoAR cPSD| 42578591

Exercise 10
Aim:
A. Create Jenkins pipeline by creating Pipeline script as well as
Declarative Script.
B. Configure Jenkins pipeline setup by executing the declarative script that
is stored in Github cloud.
Tools Required: Jenkins, Java 11, Github cloud account.
Theory:
Jenkins: Jenkins is an open-source automation server. It helps automate the
parts of software development related to building, testing, and deploying,
facilitating continuous integration and continuous delivery.
Procedure:
Step1: First download the Jenkins file from the webpage:
https://www.jenkins.io/download/ of version 2.361.3 with LTS (Long term
support) of extension war file. This was discussed on exercise -7.

Step-2: Now open the command prompt and change the directory to Jenkins
folder and type the command as:
>java -jar Jenkins.war
And then click enter. It executes its operation as shown in below:
lOMoAR cPSD| 42578591

Step-3: And then now open the browser and type the address as:
http://localhost:8080/

Step-4: Click on new item and name your item (in my case I named it as Jen
Pipeline) and select as a pipeline project.
lOMoAR cPSD| 42578591

Step-5: Go to Dashboard, under it click on Manage Jenkins and click manage


plugins in it. So at available search for stage view and check it and install it
without restart.

Install Job and stage Monitoring plugin also as above process.


lOMoAR cPSD| 42578591

Another plugin named pipeline API install it as above process.


Step-5: Now in dashboard click on configure and in it click on pipeline under
definition select it as Pipeline script and in script select it as Hello World and
click on apply and save.

Step-6: Now click on Build Now and then click on the output number to see
console output.
lOMoAR cPSD| 42578591

Now check it for console output.


lOMoAR cPSD| 42578591

Stage view:

Declarative Pipeline:
It has limited predefined structure.

Step-1: Go to github cloud and create a new repository named Jenkins-Declarative-


Pipeline and add a new file in that repository and named it as Jenkins file or your
own name. Paste this code in to that file and commit the file.
lOMoAR cPSD| 42578591

The code is:


pipeline
{
agent
any
stages
{
stage('Check
Validate'){ steps{
echo 'Validating the Program'
}
}
stage('Compilation'){
steps{
echo 'Compiling the Program'
}
}
stage('Installation'){
steps{
echo 'Installing the Program'
}
}
stage('Deploy'
){ steps{
echo 'Deploying the Program'
}
}
}

Copy the code into github file.


lOMoAR cPSD| 42578591

Step-2: Go to Jenkins homepage and create a pipeline project named as


Jen_Declarative. Now go to configuration under it goto Advanced Project Options.
In it go to pipeline under Definition select Pipeline script from SCM -> under SCM
select Git in it paste repository url of github.
lOMoAR cPSD| 42578591

At credentials click on Add select Jenkins. So it opens box as below pic.

Select kind as username with password or your wish.


If username with password give username and password of Github. And then click on
add.
And select Credentials as your added github credentials, and select it.
lOMoAR cPSD| 42578591

Step-3: Under Branches to build at branch specifier type the branch name in which
the file is existed. At my case it is main branch.

Step-4: Click on Apply and save. And click Build Now.

The full stage view is:


lOMoAR cPSD| 42578591

And to check the console output click on output file and click console output.

Conclusion:
We conclude that we learn how to implement pipelines in Jenkins and how to
declare a Declarative pipeline with stages.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy