0% found this document useful (0 votes)
10 views22 pages

Agile Software Development Overview

The document outlines the principles and practices of Agile software development, emphasizing its iterative nature and focus on collaboration, customer feedback, and adaptability. It contrasts Agile with the traditional Waterfall model, highlighting Agile's ability to deliver working software incrementally through sprints. Additionally, it discusses the integration of DevOps practices for automating the software development lifecycle, continuous integration, and continuous delivery, along with the tools and methodologies that support these processes.
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)
10 views22 pages

Agile Software Development Overview

The document outlines the principles and practices of Agile software development, emphasizing its iterative nature and focus on collaboration, customer feedback, and adaptability. It contrasts Agile with the traditional Waterfall model, highlighting Agile's ability to deliver working software incrementally through sprints. Additionally, it discusses the integration of DevOps practices for automating the software development lifecycle, continuous integration, and continuous delivery, along with the tools and methodologies that support these processes.
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

III CSE Allied Branches Continuous Integration and Continuous Delivery using DevOps Lab

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

Exercise 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.
Agile software development is one of the most effective and reliable processes to turn a vision for
business needs into software solutions. The term ―Agile‖ describes software development approaches
that employ continual planning, improvement, learning, evolutionary development, team collaboration,
and early delivery. The method encourages flexible responses to change.

In Agile software development, four main values are emphasized:


 Individual and team interactions over processes and tools;
 Working software over comprehensive documentation;
 Customer collaboration over contract negotiation;
 Responding to change over following a plan.

How Does Agile Work in Software Development?


Many people think that Agile is restricted only to software development. This is not true. Agile is a
mindset that can be used in any project that requires working together to get better results. It can be
applied in any sector, from healthcare or construction to the manufacturing field.
Enterprises that deal with software development companies use Agile in their projects to be focused on
incremental delivery, continual planning, collaboration, and learning.
The method can provide amazing results by including multiple feedback instances throughout the
development cycle. Agile software development is focused on creating MVPs (minimum viable
products) that pass through iterations, each of which provides incremental value.

What Are the Roots of the Agile Software Development Concept?


Agile SDLC
Agile software development lifecycle (SDLC) requires collaborative decision-making and development
over several short cycles or sprints.
Agile SDLC is based on a cyclical development approach to software in iterations instead of all in one
shot. Teams usually work in multiple cycles that last for 2-4 weeks. Developers are focused on the
essential features at any given moment instead of going ―according to plan.‖
Agile software development is represented with various methodologies, including:
 Agile Modeling
 Kanban
 Scrum
VLITS, Vadlamudi. Page 1
III CSE Allied Branches Continuous Integration and Continuous Delivery using DevOps Lab

 XP – Extreme Programming
 Scrumban
 Adaptive Software Development
 DAD – Disciplined Agile Delivery
 DSDM – Dynamic Systems Development
 Feature Driven Development
 Lean Software Development
Every methodology has its own goal but the main goal for all is to adapt to change and deliver working
software — as quickly as possible.

Waterfall SDLC versus Agile SDLC: defining the difference between two approaches.
Waterfall
The traditional Waterfall life cycle contains 5 stages:
 Requirement analysis
 Design
 Implementation
 Verification
 Maintenance
All these stages may last any amount of time. Before reaching the implementation stage, it may take
weeks or months. The Waterfall SDLC isn‘t designed with speed in mind. It looks quite a rationale for
complex software projects, where we strive to avoid a brand destroying fiasco.
Agile
 The key characteristic of the Agile model is that the development process breaks larger projects
down into smaller sprints. Something valuable is produced at the end of each iteration.
 Any product solution produced during a sprint should have a chance to be introduced to the world
to receive users‘ or stakeholders‘ feedback. This process should be repeated with every sprint.
 Agile is strictly sequenced in comparison with the traditional model. We cannot start design until
research is complete as well as development cannot commence until all designs are approved.
 In Agile, business people, developers, and designers work together simultaneously. The Agile
development cycle looks like this:
 Project planning
 Creating a product roadmap
 Release planning
 Sprint planning
 Daily meetings
 Sprint Review

Agile Software Development Process Flow:


 Concept: The project should be envisioned and thoroughly prioritized.
 Inception: We should determine team members, provide funds, and discuss initial environments
and requirements.

VLITS, Vadlamudi. Page 2


III CSE Allied Branches Continuous Integration and Continuous Delivery using DevOps Lab

 Iteration (construction): Developers deliver working software based on feedback and iteration
requirements.
 Release: This stage includes QA testing, training (internal and external), documentation,
development, and the final release of the iteration.
 Production with the ongoing support of the software.
 Retirement includes completing activities and customer notification.

Agile Iteration Workflow:


During the software development lifecycle in Agile, multiple iterations take place. Each of them follows
its own workflow. It is important during every iteration that the business stakeholders and clients provide
feedback to guarantee that features meet their needs.
The Agile iteration process flow may look like:
 Requirements: we have to determine them for the iteration based on the product backlog, sprint
backlog, feedback of customers and stakeholders.
 Development and design start based on the defined requirements.
 Testing includes QA testing, internal and external training, and documentation development.
 Delivery is time to deliver the working iteration into production.
 Feedback: At this stage, we should accept customer and stakeholder feedback and work it into
the requirements of the next iteration.

Exercise 2:
Get a working knowledge of using extreme automation through XP programming practices of test first
development, refactoring and automating test case writing.

In agile testing, the word "Agile" primarily signifies something that can be performed quickly and
immediately, but also in the area of software development.

The core-functional agile team implements it in order to test the software product and its several modules.
The implementation of agile testing makes sure to deliver a high quality product as bugs or defects get
deleted in the initial stage of the project itself.

Unlike the Waterfall model, Agile Testing can create at the beginning of the project with endless
incorporation between development and testing. It is not a sequential but the continuous process.

The agile testing process is a smart way of testing complicated software, which accepts more effective
results as compared to the traditional testing procedures.
VLITS, Vadlamudi. Page 3
III CSE Allied Branches Continuous Integration and Continuous Delivery using DevOps Lab

The execution of agile testing will help us identify the initial error and elimination, giving better results in
less development time and costs.
Principles of Agile Testing
Agile Testing includes various different principles that help us to increase the productivity of our
software.

How is Agile Methodology used in Testing?


Agile Testing is specified as an advanced and dynamic type of Testing that is performed regularly
throughout every iteration of the SDLC (Software Development Life Cycle) by the agile test engineers.
If we deliver the software quickly with the best of the attributes, and the customer satisfaction is the
primary concern at some stage in the agile testing process.
Agile Testing Methodologies
When we are executing the agile testing, the team takes help from several agile methodologies, which
support them in accomplishing the precise results.
Some of the effective agile testing methodologies are:

1. Extreme Programming (XP) is an agile software development methodology that aims to produce
higher quality software and improve the quality of life for the development team. It's related to
Agile as one of its implementations, sharing core values like flexibility, customer focus, and
iterative development.

VLITS, Vadlamudi. Page 4


III CSE Allied Branches Continuous Integration and Continuous Delivery using DevOps Lab

2. Test-first development in XP means writing tests before writing the actual code. This differs
from traditional approaches where testing often comes after coding. It ensures that code is testable
from the start and helps developers focus on requirements.
3. Test-Driven Development (TDD) involves: a) Write a failing test b) Write the minimum code to
pass the test c) Refactor the code. This cycle is repeated for each new feature or functionality.
4. Continuous integration in XP involves frequently merging code changes into a central
repository, after which automated builds and tests are run. This helps detect and address
integration issues early.
5. Refactoring is the process of restructuring existing code without changing its external behavior.
It's important for improving code readability, reducing complexity, and facilitating future changes.
6. Pair programming involves two programmers working together at one workstation. Benefits
include improved code quality, knowledge sharing, and reduced errors.
7. User stories in XP are simple descriptions of a feature told from the perspective of the user. They
guide development and form the basis for creating acceptance tests.
8. Automated testing in XP involves using software tools to execute pre-scripted tests on a software
application. Types typically automated include unit tests, integration tests, and acceptance tests.
9. Unit testing focuses on testing individual components or functions in isolation, while acceptance
testing verifies that the software meets the customer's requirements and works as a whole.
10. XP handles changing requirements through short development cycles, continuous customer
involvement, and maintaining a flexible codebase through practices like refactoring.
11. Common tools for automating test case writing include JUnit for Java, NUnit for .NET, Selenium
for web applications, and frameworks like Robot Framework or Cucumber for behavior-driven
development.
12. Continuous refactoring involves regularly cleaning and improving code. It's crucial for
maintaining code quality, preventing technical debt, and keeping the codebase adaptable to
changes.
13. XP addresses technical debt through practices like continuous refactoring, pair programming, and
maintaining coding standards, which help prevent debt accumulation and facilitate its repayment.
14. Coding standards in XP ensure consistency across the codebase, making it easier to understand,
maintain, and refactor. They also facilitate automated testing by promoting clean, well-structured
code.
15. Sustainable pace in XP refers to working at a pace that the team can maintain indefinitely without
burnout. It's crucial for long-term productivity, code quality, and team morale.

Example 1: A simple calculator program developed using TDD

test_calculator.py
import unittest
from calculator import Calculator

class TestCalculator([Link]):
def setUp(self):

VLITS, Vadlamudi. Page 5


III CSE Allied Branches Continuous Integration and Continuous Delivery using DevOps Lab

[Link] = Calculator()

def test_add(self):
[Link]([Link](2, 3), 5)
[Link]([Link](-1, 1), 0)

def test_subtract(self):
[Link]([Link](5, 3), 2)
[Link]([Link](1, 5), -4)

[Link]
class Calculator:
def add(self, a, b):
return a + b

def subtract(self, a, b):


return a - b

Example 2: A simple program that calculates the total price of items in a shopping cart, including a
discount if applicable.

class ShoppingCart:
def __init__(self):
[Link] = []

def add_item(self, name, price):


[Link]((name, price))

def calculate_total(self):
total = 0
for item in [Link]:
total += item[1]
if total > 100:
total = total * 0.9
return total

# Test
cart = ShoppingCart()
cart.add_item("Book", 50)
cart.add_item("Laptop", 1000)
print(f"Total: ${cart.calculate_total()}")

Now, let's refactor this code to improve its design and make it more flexible:
VLITS, Vadlamudi. Page 6
III CSE Allied Branches Continuous Integration and Continuous Delivery using DevOps Lab

class Item:
def __init__(self, name, price):
[Link] = name
[Link] = price

class DiscountStrategy:
def apply_discount(self, total):
if total > 100:
return total * 0.9
return total

class ShoppingCart:
def __init__(self, discount_strategy=DiscountStrategy()):
[Link] = []
self.discount_strategy = discount_strategy

def add_item(self, item):


[Link](item)

def calculate_total(self):
total = sum([Link] for item in [Link])
return self.discount_strategy.apply_discount(total)

# Test
cart = ShoppingCart()
cart.add_item(Item("Book", 50))
cart.add_item(Item("Laptop", 1000))
print(f"Total: ${cart.calculate_total()}")

To run this program in Eclipse, you'll need to follow these steps:

1. Create a new Python project in Eclipse.


2. Create two new Python files in your project: "test_calculator.py" and "[Link]".
3. Copy the provided code into each respective file.
4. To run the unit tests:
o Right-click on the "test_calculator.py" file in the Project Explorer.
o Select "Run As" > "Python unit-test".

Eclipse should then execute the unit tests and show you the results in the console and in the "Python Unit
Test" view.

VLITS, Vadlamudi. Page 7


III CSE Allied Branches Continuous Integration and Continuous Delivery using DevOps Lab

If you want to run the Calculator class directly (though in this case, there's no main method to execute),
you would:

 Right-click on the "[Link]" file.


 Select "Run As" > "Python Run".

However, since there's no main method or direct execution code in the Calculator class, you won't see any
output from running it this way.

Exercise 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.
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

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 tests done by development and delivery pipeline.

Continuous delivery and automation:

VLITS, Vadlamudi. Page 8


III CSE Allied Branches Continuous Integration and Continuous Delivery using DevOps Lab

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:
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, eclipse 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


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.

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

VLITS, Vadlamudi. Page 9


III CSE Allied Branches Continuous Integration and Continuous Delivery using DevOps Lab

In the context of DevOps and modern software development:


 Configuring your web application properly ensures that it runs efficiently and securely across
different environments.
 Using Git for version control is crucial for managing code changes, facilitating team collaboration,
and enabling practices like continuous integration and deployment.

The process of configuring a web application and setting up version control using Git: This process
includes creating branches for development and features, making changes, committing those changes, and
merging them back into the main line of development.

1. Set up your project: First, create a directory for your web application.
mkdir my-web-app
cd my-web-app

2. Initialize Git: Initializing Git, creates a new Git repository in your current directory. This sets up
a .git directory in your project folder, which is where Git stores all the necessary metadata for
version control.
git init

3. Create a .gitignore file: A .gitignore file specifies intentionally untracked files that Git should
ignore. This is useful for several reasons:
 Prevent cluttering your repository with unnecessary files
 Avoid committing sensitive information (like API keys)
 Improve performance by not tracking large or frequently changing files
 Prevent conflicts with files that are machine-specific

echo "# Ignore compiled files


*.class
*.jar
*.war
# Ignore build directories
/target/
/build/

# Ignore IDE files


.idea/
*.iml
.vscode/" > .gitignore

This creates a basic .gitignore file to exclude common files and directories you don't want in version
control.

VLITS, Vadlamudi. Page 10


III CSE Allied Branches Continuous Integration and Continuous Delivery using DevOps Lab

4. Add your project files: Create some initial files for your project.
Example:
[Link]
echo "<html><body><h1>My Web App</h1></body></html>" > [Link]
Here echo command is used to print a string, ‗>‘ to redirect the output to a file in the current working
directory.
[Link]
echo "public class Main { public static void main(String[] args) { } }" > [Link]

Then add these files to Git:


git add .
This command tells Git to track all files in the current directory and all subdirectories, staging any new,
modified, or deleted files for the next commit.

5. Make your first commit: This command will create a new commit with all the changes you
previously staged (using commands like git add). The commit will be labeled with the message you
provided, which should briefly describe what changes are included in this commit.
git commit -m "Initial commit with basic project structure"

6. Set up a remote repository: Go to GitHub (or your preferred Git hosting service) and create a new
repository. Then link your local repository to it:
git remote add origin [Link]
git push -u origin master
Replace 'your-username' with your actual username. These commands are used to connect your local Git
repository to a remote repository on GitHub and push your local commits to it. ‗-u‘ sets up tracking,
linking your local master branch to the remote master branch.

7. Create a development branch: The command creates a new branch called ‗development‘ in your
Git repository and immediately switches to it.
git checkout -b development
After running this command, any new commits you make will be on the "development" branch
instead of the "master" (or "main") branch.
8. Make some changes: Edit your [Link] file:
[Link]
echo "<html><body><h1>My Web App</h1><p>Welcome to my web app!</p></body></html>"

9. Commit these changes:


git add [Link]
git commit -m "Added welcome message to homepage"

10. Push the development branch:


VLITS, Vadlamudi. Page 11
III CSE Allied Branches Continuous Integration and Continuous Delivery using DevOps Lab

git push -u origin development

11. Create a feature branch:


git checkout -b feature/add-footer

12. Make changes in this feature branch:


[Link]
echo "<html><body><h1>My Web App</h1><p>Welcome to my web app!</p><footer>Copyright
2024</footer></body></html>"
13. Commit these changes:
git add [Link]
git commit -m "Added footer to homepage"

14. Push the feature branch: It is creating a more specifically named feature branch. Using this naming
convention helps organize branches, especially in larger projects with multiple ongoing features or
fixes.
git push -u origin feature/add-footer

15. Merge the feature into development: This command is used to merge the changes from the
‗feature/add-footer‘ branch into the current branch(development).
git checkout development
git merge feature/add-footer
git push origin development

16. Prepare for release:


git checkout master
git merge development
git push origin master

17. Create a release tag: These commands are used to create an annotated tag with some message in
your Git repository and push it to the remote repository.
git tag -a v1.0 -m "Version 1.0 release"
git push origin v1.0

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.
Step 1: Set up the project: a. Go to [Link]
b. Choose the following options:
VLITS, Vadlamudi. Page 12
III CSE Allied Branches Continuous Integration and Continuous Delivery using DevOps Lab

 Project: Maven
 Language: Java
 Spring Boot: 2.5.5 (or the latest stable version)
 Group: [Link]
 Artifact: cicd-demo
 Packaging: Jar
 Java: 8 (or your installed version) c. Add Dependencies: Spring Web d. Click "Generate" and
download the zip file e. Extract the zip file and import it into Eclipse as a Maven project
 Folder Structure:
Cicd-Demo/

├── src/
│ ├── main/
│ │ ├── java/
│ │ │ └── com/
│ │ │ └── example/cicddemo
│ │ │ ├── [Link]
│ │ │ └── controller/
│ │ │ └── [Link]
│ │ └── resources/
│ │ └── [Link]
│ │
│ └── test/
│ └── java/
│ └── com/
│ └── example/cicddemo
│ └── [Link]

├── [Link]
└── Jenkinsfile

Step 2: Create a simple REST controller: Create a new Java class [Link] in
src/main/java/com/example/cicddemo:

package [Link];
import [Link];
import [Link];
@RestController
public class HelloController {
@GetMapping("/hello")
public String hello() {
return "Hello, CI/CD!";

VLITS, Vadlamudi. Page 13


III CSE Allied Branches Continuous Integration and Continuous Delivery using DevOps Lab

}
}

Step 3: Create a test class: Create [Link] in src/test/java/com/example/cicddemo:


package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import static [Link];
import static [Link];
import static [Link];

@SpringBootTest
@AutoConfigureMockMvc
public class HelloControllerTest {
@Autowired
private MockMvc mockMvc;
@Test
public void testHelloEndpoint() throws Exception {
[Link](get("/hello"))
.andExpect(status().isOk())
.andExpect(content().string("Hello, CI/CD!"));
}
}

Step 4: Maven Build Script ([Link]):


<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="[Link]
xmlns:xsi="[Link]
xsi:schemaLocation="[Link] [Link]
[Link]">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>[Link]</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>[Link]</groupId>
<artifactId>cicd-demo</artifactId>

VLITS, Vadlamudi. Page 14


III CSE Allied Branches Continuous Integration and Continuous Delivery using DevOps Lab

<version>0.0.1-SNAPSHOT</version>
<name>cicd-demo</name>
<description>Demo project for Spring Boot</description>
<url/>
<licenses>
<license/>
</licenses>
<developers>
<developer/>
</developers>
<scm>
<connection/>
<developerConnection/>
<tag/>
<url/>
</scm>
<properties>
<[Link]>17</[Link]>
</properties>
<dependencies>
<dependency>
<groupId>[Link]</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>[Link]</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>[Link]</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

VLITS, Vadlamudi. Page 15


III CSE Allied Branches Continuous Integration and Continuous Delivery using DevOps Lab

Step 5: Add PMD plugin to [Link]: Add the following inside the <build><plugins> section of your
[Link]:

<plugin>
<groupId>[Link]</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.14.0</version>
<configuration>
<failOnViolation>true</failOnViolation>
<printFailingErrors>true</printFailingErrors>
</configuration>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>

Step 6: Jenkins Pipeline Script (Jenkinsfile):


pipeline {
agent any

stages {
stage('Checkout') {
steps {
checkout scm
}
}
stage('Build') {
steps {
sh 'mvn clean package'
}
}
stage('Static Analysis') {
steps {
sh 'mvn pmd:check'
}
}
stage('Unit Tests') {
steps {

VLITS, Vadlamudi. Page 16


III CSE Allied Branches Continuous Integration and Continuous Delivery using DevOps Lab

sh 'mvn test'
}
}
stage('Deploy') {
steps {
sh 'java -jar target/[Link] &'
}
}
}
post {
always {
junit '**/target/surefire-reports/*.xml'
}
}
}

Step 7: Create Sample Application(Main method class) Code:


package [Link];
import [Link];
import [Link];
@SpringBootApplication
public class Application {
public static void main(String[] args) {
[Link]([Link], args);
}
}

Step 8: Create a build script: Create a file named [Link] in the project root:
mvn clean compile
mvn pmd:check
mvn test
mvn package
Step 9: Run the build script: Open a terminal in your project directory and run: [Link]

Step 10: Run the application: After the build is successful, run:
mvn spring-boot:run

Step 11: Test the application: Open a web browser and go to [Link]
Output: "Hello, CI/CD!"

Build stages:
1. mvn clean compile: Cleans the project and compiles the source code

VLITS, Vadlamudi. Page 17


III CSE Allied Branches Continuous Integration and Continuous Delivery using DevOps Lab

2. mvn pmd:check: Runs the PMD static code analysis


3. mvn test: Executes the unit tests
4. mvn package: Packages the application into a JAR file

Experiment 7: Implementing CI/CD with Java and Jenkins 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.

Objective: Configure Jenkins and create a CI/CD pipeline for a simple Java application.

Prerequisites:
1. Java JDK 8 or later
2. Maven
3. Git
4. Jenkins

Step-by-step Procedure:
1. Create a Simple Java Application: a. Create a new directory for your project:
mkdir simple-java-app
cd simple-java-app

b. Create a Maven project structure:

mvn archetype:generate -DgroupId=[Link] -DartifactId=simple-java-app -


DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

c. Navigate to the project directory:

cd simple-java-app

d. Replace the contents of src/main/java/com/example/[Link] with:

package [Link];
public class App {
public static String getGreeting() {
return "Hello, CI/CD World!";
}
public static void main(String[] args) {
[Link](getGreeting());
}
}

e. Replace the contents of src/test/java/com/example/[Link] with:


VLITS, Vadlamudi. Page 18
III CSE Allied Branches Continuous Integration and Continuous Delivery using DevOps Lab

package [Link];
import static [Link];
import [Link];

public class AppTest {


@Test
public void testGetGreeting() {
assertEquals("Hello, CI/CD World!", [Link]());
}
}

f. Update the [Link] file to use a more recent version of JUnit and add the Maven Surefire Plugin:

<project>
...
<properties>
<[Link]>1.8</[Link]>
<[Link]>1.8</[Link]>
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>[Link]</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
</plugin>
</plugins>
</build>
...
</project>

g. Initialize a Git repository and commit your code:

VLITS, Vadlamudi. Page 19


III CSE Allied Branches Continuous Integration and Continuous Delivery using DevOps Lab

git init
git add .
git commit -m "Initial commit"

h. Create a new repository on GitHub (or your preferred Git hosting service) and push your code:

git remote add origin [Link]


git push -u origin master
2. Configure Jenkins:
a. Install Jenkins and start it.
b. Access Jenkins at [Link] and complete the initial setup.
c. Install necessary plugins: Go to "Manage Jenkins" > "Manage Plugins" > "Available" and
install:
o Git plugin
o Maven Integration plugin
o Pipeline plugin

d. Configure Java and Maven: Go to "Manage Jenkins" > "Global Tool Configuration"

o Add JDK (uncheck "Install automatically"): Name: JDK8 JAVA_HOME:


/path/to/your/java/home
o Add Maven (uncheck "Install automatically"): Name: Maven3 MAVEN_HOME:
/path/to/your/maven/home
3. Create a Jenkins Pipeline: a. On the Jenkins dashboard, click "New Item" b. Enter a name for
your pipeline (e.g., "simple-java-app-pipeline"), select "Pipeline", and click "OK" c. In the
configuration page, scroll to the "Pipeline" section d. Select "Pipeline script" and enter the
following script:

pipeline {
agent any

tools {
jdk 'JDK8'
maven 'Maven3'
}

stages {
stage('Checkout') {
steps {
git '[Link]
}
}

VLITS, Vadlamudi. Page 20


III CSE Allied Branches Continuous Integration and Continuous Delivery using DevOps Lab

stage('Build') {
steps {
sh 'mvn clean compile'
}
}

stage('Test') {
steps {
sh 'mvn test'
}
post {
always {
junit '**/target/surefire-reports/TEST-*.xml'
}
}
}

stage('Package') {
steps {
sh 'mvn package'
}
post {
success {
archiveArtifacts 'target/*.jar'
}
}
}
}
}

e. Replace '[Link] with your actual repository URL


f. Click "Save"

4. Run the Pipeline:


a. On the pipeline page, click "Build Now"
b. Jenkins will start executing the pipeline. You can see the progress in the "Stage View"
c. Once completed, you can:
o View the console output
o Check the test results
o Download the archived JAR file

VLITS, Vadlamudi. Page 21


III CSE Allied Branches Continuous Integration and Continuous Delivery using DevOps Lab

Explanation:

1. The Java application is a simple "Hello, CI/CD World!" program with a unit test.
2. The Jenkins pipeline has four stages:
o Checkout: Retrieves the code from GitHub
o Build: Compiles the Java code
o Test: Runs the unit tests and publishes the results
o Package: Creates a JAR file and archives it
3. Each stage in the pipeline corresponds to a step in the CI/CD process:
o Continuous Integration: Checkout, Build, and Test stages
o Continuous Delivery: Package stage (in a real-world scenario, you might add Deploy
stages)

VLITS, Vadlamudi. Page 22

You might also like