Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Empty_file
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

72 changes: 59 additions & 13 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,30 +1,76 @@
pipeline {
agent any
agent { label 'dev' } // Specify the label of your Jenkins Slave. Modify 'dev' if you use a different label.

environment {
MAVEN_HOME = tool name: 'Maven' // Ensure 'Maven' matches the name in Jenkins tool configuration.
SONARQUBE_SERVER = 'Sonar' // Define the SonarQube server ID.
SONAR_SCANNER_HOME = tool name: 'SonarScanner' // Ensure 'SonarScanner' matches the name in Jenkins tool configuration.
ARTIFACTORY_SERVER = 'Artifactory' // Define Artifactory server ID.
SONAR_TOKEN = 'sqa_bcb97e97554c1eeff5b2a5cd9c0a23d2d59b749b' // SonarQube token
}

stages {
stage ('checkout') {
stage('Checkout') {
steps {
echo "This is checkout stage"
// Checkout the source code from your repository
git url: 'https://github.com/shashank1553/java-onlinebookstore.git', branch: 'main'
}
}
stage ('build') {

stage('Build') {
steps {
echo "This is build stage "
// Build the Maven project
sh "${MAVEN_HOME}/bin/mvn clean install"
}
}
stage ('sonarscan') {

stage('SonarQube Analysis') {
steps {
echo "This is sonarscan stage "
// Run SonarQube analysis
withSonarQubeEnv(SONARQUBE_SERVER) {
sh "${MAVEN_HOME}/bin/mvn sonar:sonar -Dsonar.login=${SONAR_TOKEN}"
}
}
}
stage ('push') {
}

stage('Deploy to Artifactory') {
steps {
echo "This is push stage"
script {
// Upload artifacts to JFrog Artifactory
rtUpload (
serverId: ARTIFACTORY_SERVER,
spec: '''{
"files": [{
"pattern": "target/onlinebookstore.war", // Path to the artifact to upload
"target": "maven-releases/onlinebookstore/" // Target repository path in Artifactory
}]
}'''
)
}
}
}
stage ('deploy') {

stage('Deploy to Tomcat') {
steps {
echo "This is deploy stage "
script {
// Deploy the WAR file to Apache Tomcat server
sh """
curl -u admin:Admin12345 --upload-file target/onlinebookstore.war "http://35.171.26.114:8081/artifactory/maven-releases/onlinebookstore/"
"""
}
}
}
}
}

post {
always {
cleanWs() // Clean the workspace after the build
}
success {
echo "Build, Analysis, and Deployment succeeded!"
}
failure {
echo "Build failed. Check the logs!"
}
}
}
151 changes: 78 additions & 73 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,75 +1,80 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>onlinebookstore</groupId>
<artifactId>onlinebookstore</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<finalName>onlinebookstore</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.github.jsimone</groupId>
<artifactId>webapp-runner</artifactId>
<version>8.0.30.2</version>
<destFileName>webapp-runner.jar</destFileName>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.1</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>onlinebookstore</groupId>
<artifactId>onlinebookstore</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>

<build>
<sourceDirectory>src/main/java</sourceDirectory>
<finalName>onlinebookstore</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.6.0</version> <!-- Updated version -->
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.github.jsimone</groupId>
<artifactId>webapp-runner</artifactId>
<version>8.0.30.2</version>
<destFileName>webapp-runner.jar</destFileName>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.3.1</version> <!-- Updated version -->
<configuration>
<warSourceDirectory>src/main/webapp</warSourceDirectory> <!-- Updated to default directory -->
</configuration>
</plugin>
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>4.0.0.4121</version> <!-- Ensure this is the latest version or as per your requirements -->
</plugin>
</plugins>
</build>

<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.3.7</version>
</dependency>


<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.28</version>
</dependency>


<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
</dependencies>
</project>
<dependencies>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.3.7</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.28</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version> <!-- Updated version to 4.0.1 -->
<scope>provided</scope> <!-- Usually provided by the servlet container -->
</dependency>
</dependencies>
</project>