forked from sudheer76R/java-example
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjenkinsrsync2
More file actions
54 lines (46 loc) · 1.46 KB
/
jenkinsrsync2
File metadata and controls
54 lines (46 loc) · 1.46 KB
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
pipeline {
agent any
environment {
TOMCAT_USER = 'ec2-user'
TOMCAT_HOST = '52.66.8.70'
TOMCAT_PATH = '/home/ec2-usser/tomcat/webapps/'
ARTIFACT_NAME = 'works-with-heroku-1.0.war'
}
stages {
stage('Build') {
steps {
echo 'Building the project...'
// Assuming Maven is used
sh 'mvn clean package'
}
}
stage('Deploy') {
steps {
script {
def artifactPath = "target/${env.ARTIFACT_NAME}"
echo "Deploying ${artifactPath} to ${env.TOMCAT_HOST}..."
// Deploy artifact using rsync
sh """
rsync -avz --delete ${artifactPath} ${env.TOMCAT_USER}@${env.TOMCAT_HOST}:${env.TOMCAT_PATH}
"""
}
}
}
stage('Restart Tomcat') {
steps {
script {
echo "Restarting Tomcat on ${env.TOMCAT_HOST}..."
// Restart Tomcat (Optional)
sh """
ssh ${env.TOMCAT_USER}@${env.TOMCAT_HOST} 'sudo systemctl restart tomcat'
"""
}
}
}
}
post {
always {
echo 'Pipeline execution finished.'
}
}
}