DevOps Exp 8
DevOps Exp 8
ID -VU4F2223031 TE IT A | Batch B
Experiment No. 8
Theory -
1. Maven: Maven is a powerful build tool used primarily for Java projects. It manages project
builds, dependencies, packaging, testing, and deployment through a declarative
configuration file, pom.xml. The key idea behind Maven is to provide an easy way to
automate these tasks, making the build process reproducible and consistent.
3. Pipeline: A Jenkins pipeline is a suite of automated tasks (like build, test, package, and
deploy) defined in a script (Jenkinsfile). Pipelines can be either declarative (simpler, preferred
for most use cases) or scripted.
Steps -
2. Set Up Jenkins
Install Required Plugins (like Git Plugin and Maven Integration Plugin) by going to
Manage Jenkins > Manage Plugins.
Configure Maven in Jenkins by going to Manage Jenkins > Tools and Scrolling down
to Maven click on Add Maven, provide a name, and install Maven automatically.
POM.XML
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>percentage-giver</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>percentage-giver</name>
<url>http://maven.apache.org</url>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<configuration>
<mainClass>com.example.App</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>
Jenkinsfile.txt
pipeline {
agent any
tools {
maven 'MAVEN_HOME' // Make sure 'Maven' is configured in Jenkins
}
parameters {
string(name: 'CGPA', defaultValue: '', description: 'Enter your CGPA')
}
stages {
stage('Checkout') {
steps {
git branch: 'main', url: 'https://github.com/Rutvikgg/percentage-giver.git' // Replace with your GitHub repo URL
}
}
stage('Build') {
steps {
// Use 'bat' for Windows instead of 'sh'
bat 'mvn clean compile'
}
}
stage('Run App') {
steps {
// Use 'bat' and Windows-specific command for running Java application
bat 'mvn exec:java -Dexec.mainClass="com.example.App"'
}
}
}
post {
success {
echo 'Pipeline executed successfully.'
}
failure {
echo 'Pipeline failed.'
}
}
}
App.java
package com.example;
// Conversion factor can vary by institution, here we assume a factor of 9.5 for the conversion
public static final double CONVERSION_FACTOR = 9.5;
Conclusion: