forked from giridharpatnaik183/webAppExample
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
70 lines (62 loc) · 2.61 KB
/
Jenkinsfile
File metadata and controls
70 lines (62 loc) · 2.61 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
pipeline {
agent any
tools {
maven 'maven'
}
environment {
TOMCAT_WEBAPPS = '/var/lib/tomcat9/webapps' // Set this to the actual path of the Tomcat webapps directory
SSH_CREDENTIALS = 'my_ssh_credentials'
TOMCAT_SERVER = '54.89.78.184'
TOMCAT_CREDENTIALS_ID = '058ddaec-e159-4481-b9e6-801f583943b6'
TOMCAT_URL = 'http://54.89.78.184:8090/'
}
stages {
stage('SCM Checkout') {
steps {
checkout([$class: 'GitSCM', branches: [[name: '*/master'], [name: '*/qa']], userRemoteConfigs: [[url: 'https://github.com/giridharpatnaik183/webAppExample.git']]])
}
}
stage('Build') {
steps {
sh 'mvn clean package'
}
}
stage('Deploy to Tomcat Server') {
steps {
script {
def targetDir
if (env.BRANCH_NAME == 'master') {
targetDir = "${TOMCAT_WEBAPPS}/master"
} else if (env.BRANCH_NAME == 'qa') {
targetDir = "${TOMCAT_WEBAPPS}/qa"
}
sshCommand remote: TOMCAT_SERVER, userSshKey: [$class: 'StringBinding', variable: 'SSH_CREDENTIALS'], command: "mkdir -p ${targetDir} && cp -f target/*.war ${targetDir}/"
}
}
}
stage('Deploy to Tomcat via Plugin') {
steps {
deploy adapters: [tomcat9(credentialsId: TOMCAT_CREDENTIALS_ID, path: '', url: TOMCAT_URL)], contextPath: null, war: '**/*.war'
}
}
stage('Copy index.jsp') {
when {
expression { currentBuild.resultIsBetterOrEqualTo('SUCCESS') }
}
steps {
script {
def targetDir
def sourceJspPath
if (env.BRANCH_NAME == 'master') {
targetDir = "${TOMCAT_WEBAPPS}/ROOT"
sourceJspPath = "https://raw.githubusercontent.com/giridharpatnaik183/webAppExample/master/src/main/webapp/index.jsp"
} else if (env.BRANCH_NAME == 'qa') {
targetDir = "${TOMCAT_WEBAPPS}/qa"
sourceJspPath = "https://raw.githubusercontent.com/giridharpatnaik183/webAppExample/qa/src/main/webapp/index.jsp"
}
sshCommand remote: TOMCAT_SERVER, userSshKey: [$class: 'StringBinding', variable: 'SSH_CREDENTIALS'], command: "curl -o ${targetDir}/index.jsp ${sourceJspPath}"
}
}
}
}
}