forked from DevOps-E2E/Maven-Webapp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
56 lines (52 loc) · 1.48 KB
/
Jenkinsfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
pipeline {
agent any
environment {
REPO_URL = 'REPO-URL'
BRANCH = 'main'
WAR_NAME = 'webapp.war'
WAR_SOURCE_PATH = "${env.WORKSPACE}/webapp/target/${WAR_NAME}"
TOMCAT_WEBAPP_DIR = '/home/ubuntu/apache-tomcat-10.1.24/webapps'
}
tools{
maven 'MAVEN_HOME'
}
stages {
stage('Clone Repository') {
steps {
// Clone the main branch of the repository from GitHub
git branch: "${BRANCH}", url: "${REPO_URL}"
sh 'whoami'
}
}
stage('Build WAR') {
steps {
script {
// Build the project and package it as a WAR file using Maven
sh 'mvn clean package'
}
}
}
stage('Deploy to Tomcat') {
steps {
script {
// Ensure the WAR file exists
if (!fileExists(WAR_SOURCE_PATH)) {
error "WAR file not found: ${WAR_SOURCE_PATH}"
}
// Copy the WAR file to the Tomcat webapps directory
sh """
sudo cp ${WAR_SOURCE_PATH} ${TOMCAT_WEBAPP_DIR}
"""
}
}
}
}
post {
success {
echo 'Deployment succeeded!'
}
failure {
echo 'Deployment failed!'
}
}
}