Skip to content
Open
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
95 changes: 55 additions & 40 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,72 +1,87 @@
@Library('jenkins-shared-libraries-@main') _ // Correct syntax

pipeline {
agent {
label 'king'
}
agent { label 'slave' }

environment {
TOMCAT_HOST = '172.31.3.184'
TOMCAT_USER = 'root'
TOMCAT_DIR = '/opt/apache-tomcat-8.5.98/webapps'
JAR_FILE = 'bus-booking-app-1.0-SNAPSHOT.jar' // Replace with the actual name of your JAR file
JAVA_HOME = '/usr/lib/jvm/java-17-openjdk-amd64'
MAVEN_HOME = '/usr/share/maven'
PATH = "${JAVA_HOME}/bin:${MAVEN_HOME}/bin:${env.PATH}"
}

stages {
stage('checkout') {
stage('Checkout Code') {
steps {
sh 'rm -rf bus_booking'
sh 'git clone https://github.com/sudhasanshi/bus_booking.git'
script {
pipeline1.checkscm()
}
}
}
stage('Set up Java 17') {
steps {
script {
pipeline1.setupjava()
}
}
}
}

stage('build') {
stage('Set up Maven') {
steps {
script {
def mvnHome = tool 'Maven'
def mvnCMD = "${mvnHome}/bin/mvn"
sh "${mvnCMD} clean install"
}
pipeline1.mavensetup()
}
}
}

stage('Show Contents of target') {
stage('Build with Maven') {
steps {
script {
// Print the contents of the target directory
sh 'ls -l target'
}
pipeline1.build()
}
}
}

stage('Run JAR Locally') {
stage('Upload Artifact') {
steps {
script {
// Run the JAR file using java -jar
sh "java -jar target/${JAR_FILE}"
}
uploadArtifact('target/bus-booking-app-1.0-SNAPSHOT.jar')
}
}

stage('Deploy JAR to Tomcat') {
stage('Run Application') {
steps {
script {
// Copy JAR to Tomcat server
sh "scp target/${JAR_FILE} ${TOMCAT_USER}@${TOMCAT_HOST}:${TOMCAT_DIR}/"

// SSH into Tomcat server and restart Tomcat
sh "ssh ${TOMCAT_USER}@${TOMCAT_HOST} 'bash -s' < restart-tomcat.sh"

echo "Application deployed and Tomcat restarted"
}
pipeline1.runApp()
}
}
}
}

post {
success {
echo "Build, Run, and Deployment to Tomcat successful!"
stage('Validate App is Running') {
steps {
script {
pipeline1.validateApp()
}
}
}
stage('wait') {
steps {
script {
pipeline1.waiting()
}
}
}
failure {
echo "Build, Run, and Deployment to Tomcat failed!"
stage('stoping') {
steps {
script {
pipeline1.stop()
}
}
}
stage('cleaning') {
steps {
script {
pipeline1.clean()
}
}
}
}
}