This repository has been archived by the owner on Feb 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Jenkinsfile
157 lines (140 loc) · 4.17 KB
/
Jenkinsfile
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
pipeline {
agent { label 'prod' }
parameters {
booleanParam(name: 'BUILD', defaultValue: true, description: '')
booleanParam(name: 'TEST', defaultValue: true, description: '')
booleanParam(name: 'MAVEN_DEPLOY', defaultValue: false, description: 'Deploy JAR artifacts to Maven')
}
tools {
maven 'M3'
jdk 'jdk8u152'
}
options {
buildDiscarder(logRotator(numToKeepStr: '2'))
disableConcurrentBuilds()
}
stages {
stage('Initialize') {
steps {
sh '''
echo "PATH = ${PATH}"
echo "M2_HOME = ${M2_HOME}"
'''
sh "mvn -version"
}
}
stage('Build') {
when {
expression {
params.BUILD
}
}
steps {
dir("csp-apps") {
maven_build("-DskipTests clean package")
}
}
}
stage('Unit Tests') {
when {
expression {
params.TEST
}
}
steps {
dir("csp-apps") {
maven_build("clean test")
}
}
post {
always {
junit allowEmptyResults: true, testResults: '**/target/surefire-reports/TEST-*.xml'
jacoco(execPattern: '**/*.exec')
}
}
}
stage('Acceptance Tests') {
when {
expression {
params.TEST
}
}
steps {
dir("csp-apps") {
maven_build("clean verify")
}
}
post {
always {
junit allowEmptyResults: true, testResults: '**/target/failsafe-reports/TEST-*.xml'
}
}
}
stage("Run SonarQube analysis") {
when {
expression {
params.TEST
}
}
steps {
dir("csp-apps") {
sh "mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent test"
sh "mvn sonar:sonar -Dsonar.host.url=http://sonar:9000 -Dsonar.login=acfa03872fbc02f58468cb05c21242ef4f8d5486"
}
}
}
stage('Deploy maven artifact') {
when {
expression {
params.MAVEN_DEPLOY
}
}
steps {
dir("csp-apps") {
maven_build("-DskipTests -DskipITs clean deploy")
}
}
}
}
post {
always {
notifyBuild(currentBuild.result)
deleteDir()
}
}
}
def maven_build(lifecycle) {
configFileProvider(
[configFile(fileId: 'sastix-setting.xml', variable: 'MAVEN_SETTINGS')]) {
sh """mvn -s $MAVEN_SETTINGS ${lifecycle}"""
}
}
def notifyBuild(String buildStatus = 'STARTED') {
// build status of null means successful
buildStatus = buildStatus ?: 'SUCCESSFUL'
// Default values
def colorName = 'RED'
def colorCode = '#FF0000'
def subject = "'${env.JOB_NAME} - #${env.BUILD_NUMBER}' ${buildStatus} "
def summary = "${subject} (<${env.RUN_DISPLAY_URL}|Open>)"
def details = """<p>STARTED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]':</p>
<p>Check console output at "<a href='${env.BUILD_URL}'>${env.JOB_NAME} [${env.BUILD_NUMBER}]</a>"</p>"""
// Override default values based on build status
if (buildStatus == 'STARTED') {
color = 'YELLOW'
colorCode = '#FFFF00'
} else if (buildStatus == 'SUCCESSFUL') {
color = 'GREEN'
colorCode = '#00FF00'
} else {
color = 'RED'
colorCode = '#FF0000'
}
// Send notifications
slackSend(color: colorCode, message: summary)
// emailext(
// subject: subject,
// body: details,
// recipientProviders: [[$class: 'DevelopersRecipientProvider']]
// )
}