-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathJenkinsfile
More file actions
121 lines (84 loc) · 3.33 KB
/
Jenkinsfile
File metadata and controls
121 lines (84 loc) · 3.33 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
pipeline {
agent {
docker { image 'maven:3.6.3-openjdk-8-slim' }
}
environment {
PROJECT_REPOSITORY_DIRECTORY = "eCommerce"
APPLICATION_WAR_FILE = "target/ecommerce-0.0.1.war"
APPLICATION_CONTEXT = "$WORKSPACE/$PROJECT_REPOSITORY_DIRECTORY"
}
options {
skipDefaultCheckout()
skipStagesAfterUnstable()
}
stages {
stage ('SCM Checkout') {
steps {
checkout scm
}
}
stage ('Build') {
steps {
script {
sh 'cd $APPLICATION_CONTEXT && mvn -B -DskipTests clean package'
}
}
}
stage ('Test') {
steps {
script {
sh 'cd $APPLICATION_CONTEXT && mvn clean test cobertura:cobertura -Dcobertura.report.format=xml'
}
}
post {
always {
junit '**/target/*-reports/TEST-*.xml'
step([$class: 'CoberturaPublisher', coberturaReportFile: 'eCommerce/target/site/cobertura/coverage.xml'])
}
}
}
stage ('Deploy') {
steps {
script {
def deploy_application = false
try {
echo 'Wait 5 minutes for the answer.'
timeout(time: 5, unit: 'MINUTES') {
deploy_application = input id: 'deploy_application',
message: 'Deploy the new version of the application?',
ok: 'Yes, deploy it.',
parameters: [
[
$class: 'BooleanParameterDefinition',
defaultValue: true,
successfulOnly: true,
description: 'Please confirm you agree with this.',
name: 'I agree with it.'
]
]
}
} catch (error) {
def user = error.getCauses()[0].getUser()
if( 'SYSTEM' == user.toString() ) {
// The constant SYSTEM means that the build was cancelled by timeout.
echo 'No user interaction. Build timeout.'
currentBuild.result = 'ABORTED'
throw error
}
currentBuild.result = 'UNSTABLE'
}
if ( deploy_application == true ) {
// Deploying the application
sh 'cd $APPLICATION_CONTEXT && mvn clean package'
deploy adapters: [
tomcat9(url: 'http://udacity-tomcat:8080',
credentialsId: 'tomcat')
],
war: 'eCommerce/target/*.war',
contextPath: '/'
}
} // Script
} // Steps
} // Stage
} // Stages
} // Pipeline