File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments