Skip to content

Commit 356de4d

Browse files
authored
Create jenkinsrsync2
1 parent 5a2003c commit 356de4d

1 file changed

Lines changed: 54 additions & 0 deletions

File tree

jenkinsrsync2

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
pipeline {
2+
agent any
3+
4+
environment {
5+
TOMCAT_USER = 'ec2-user'
6+
TOMCAT_HOST = '52.66.8.70'
7+
TOMCAT_PATH = '/home/ec2-usser/tomcat/webapps/'
8+
ARTIFACT_NAME = 'works-with-heroku-1.0.war'
9+
}
10+
11+
stages {
12+
stage('Build') {
13+
steps {
14+
echo 'Building the project...'
15+
// Assuming Maven is used
16+
sh 'mvn clean package'
17+
}
18+
}
19+
20+
stage('Deploy') {
21+
steps {
22+
script {
23+
def artifactPath = "target/${env.ARTIFACT_NAME}"
24+
25+
echo "Deploying ${artifactPath} to ${env.TOMCAT_HOST}..."
26+
27+
// Deploy artifact using rsync
28+
sh """
29+
rsync -avz --delete ${artifactPath} ${env.TOMCAT_USER}@${env.TOMCAT_HOST}:${env.TOMCAT_PATH}
30+
"""
31+
}
32+
}
33+
}
34+
35+
stage('Restart Tomcat') {
36+
steps {
37+
script {
38+
echo "Restarting Tomcat on ${env.TOMCAT_HOST}..."
39+
40+
// Restart Tomcat (Optional)
41+
sh """
42+
ssh ${env.TOMCAT_USER}@${env.TOMCAT_HOST} 'sudo systemctl restart tomcat'
43+
"""
44+
}
45+
}
46+
}
47+
}
48+
49+
post {
50+
always {
51+
echo 'Pipeline execution finished.'
52+
}
53+
}
54+
}

0 commit comments

Comments
 (0)