This repository has been archived by the owner on Sep 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Jenkinsfile-new
269 lines (258 loc) · 10.7 KB
/
Jenkinsfile-new
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
#!/usr/bin/env groovy
def artServer = Artifactory.server 'art-p-01'
def buildInfo = Artifactory.newBuildInfo()
def distDir = 'build/dist/'
pipeline {
libraries {
lib('jenkins-pipeline-shared')
}
environment {
SVC_NAME = "address-index-api"
ORG = "AI"
DEPLOY_NAME = "dev"
GATLING_REQUESTS_PER_SECOND = 20
GATLING_GET_ENDPOINT = "https://addressindex-api-${DEPLOY_NAME}.apps.cf1.ons.statistics.gov.uk/addresses?input=26%20FROG%20LANE%20TITCHFIELD%20PO144DU"
}
options {
//TODO: Try removing/commenting this
skipDefaultCheckout()
buildDiscarder(logRotator(numToKeepStr: '30', artifactNumToKeepStr: '30'))
timeout(time: 1, unit: 'HOURS')
ansiColor('xterm')
}
agent { label 'download.jenkins.slave' }
stages {
stage('Checkout') {
agent { label 'download.jenkins.slave' }
steps {
deleteDir()
checkout scm
script {
buildInfo.name = "${SVC_NAME}"
buildInfo.number = "${BUILD_NUMBER}"
buildInfo.env.collect()
}
colourText("info", "BuildInfo: ${buildInfo.name}-${buildInfo.number}")
stash name: 'Checkout'
}
}
stage('Build') {
agent { label 'build.sbt_0-13-13' }
steps {
unstash name: 'Checkout'
sh "sbt 'project address-index-server' clean compile universal:packageBin"
stash name: 'compiled'
}
post {
success {
colourText("info", "Stage: ${env.STAGE_NAME} successful!")
}
failure {
colourText("warn", "Stage: ${env.STAGE_NAME} failed!")
}
}
}
stage('Validate') {
failFast true
parallel {
stage('Test: Unit') {
agent { label 'build.sbt_0-13-13' }
steps {
unstash name: 'Checkout'
sh 'JAVA_TOOL_OPTIONS="-Dfile.encoding=UTF8" sbt "project address-index-server" clean compile coverage test coverageReport'
}
post {
always {
junit '**/server/target/test-reports/*.xml'
cobertura autoUpdateHealth: false,
autoUpdateStability: false,
coberturaReportFile: 'server/target/**/coverage-report/cobertura.xml',
conditionalCoverageTargets: '70, 0, 0',
failUnhealthy: false,
failUnstable: false,
lineCoverageTargets: '80, 0, 0',
maxNumberOfBuilds: 0,
methodCoverageTargets: '80, 0, 0',
onlyStable: false,
zoomCoverageChart: false
}
success {
colourText("info", "Stage: ${env.STAGE_NAME} successful!")
}
failure {
colourText("warn", "Stage: ${env.STAGE_NAME} failed!")
}
}
}
stage('Style') {
agent { label 'build.sbt_0-13-13' }
steps {
unstash name: 'Checkout'
colourText("info", "Running style tests")
sh 'sbt "project address-index-server" scalastyleGenerateConfig scalastyle'
}
post {
always {
checkstyle canComputeNew: false, defaultEncoding: '', healthy: '', pattern: 'server/target/scalastyle-result.xml', unHealthy: ''
}
}
}
stage('Scapegoat') {
agent { label 'build.sbt_0-13-13' }
steps {
unstash name: 'Checkout'
colourText("info", "Running additional tests")
sh 'sbt "project address-index-server" scapegoat'
}
post {
always {
checkstyle canComputeNew: false, defaultEncoding: '', healthy: '', pattern: 'server/target/scala-2.11/scapegoat-report/scapegoat-scalastyle.xml', unHealthy: ''
}
}
}
}
post {
success {
colourText("info", "Stage: ${env.STAGE_NAME} successful!")
}
failure {
colourText("warn", "Stage: ${env.STAGE_NAME} failed!")
}
}
}
stage('Publish') {
agent { label 'build.sbt_0-13-13' }
when {
branch "REG-1992_Move-sensitive-data-to-Gitlab"
// evaluate the when condition before entering this stage's agent, if any
beforeAgent true
}
steps {
colourText("info", "Building ${env.BUILD_ID} on ${env.JENKINS_URL} from branch ${env.BRANCH_NAME}")
colourText("info", "Will upload to registers-sbt-snapshots/uk/gov/ons/${buildInfo.name}/${buildInfo.number}/")
unstash name: 'Checkout'
sh 'sbt "project address-index-server" universal:packageBin'
sh 'find . -name "*.zip" -type f'
script {
try {
def uploadSpec = """{
"files": [
{
"pattern": "server/target/universal/*.zip",
"target": "registers-sbt-snapshots/uk/gov/ons/${buildInfo.name}/${buildInfo.number}/"
}
]
}"""
artServer.upload spec: uploadSpec, buildInfo: buildInfo
} catch (Exception e) {
echo "Caught $e"
}
}
}
post {
success {
colourText("info", "Stage: ${env.STAGE_NAME} successful!")
}
failure {
colourText("warn", "Stage: ${env.STAGE_NAME} failed!")
}
}
}
stage('Deploy: Dev') {
agent { label 'deploy.cf' }
when {
branch "REG-1843_Build-script-for-new-jenkins"
// evaluate the when condition before entering this stage's agent, if any
beforeAgent true
}
environment {
CREDS = 's_jenkins_ai_dev'
SPACE = 'Dev'
}
steps {
script {
def downloadSpec = """{
"files": [
{
"pattern": "registers-sbt-snapshots/uk/gov/ons/${buildInfo.name}/${buildInfo.number}/*.zip",
"target": "${distDir}",
"flat": "true"
}
]
}"""
artServer.download spec: downloadSpec, buildInfo: buildInfo
sh "mv ${distDir}address-index-server.zip ${distDir}${env.SVC_NAME}.zip"
}
dir('config') {
git url: "${GITLAB_URL}/AddressIndex/${env.SVC_NAME}.git", credentialsId: 'JenkinsAI__gitlab'
}
script {
cfDeploy {
credentialsId = "${this.env.CREDS}"
org = "${this.env.ORG}"
space = "${this.env.SPACE}"
appName = "addressindex-api-${this.env.DEPLOY_NAME}"
appPath = "./${distDir}/${this.env.SVC_NAME}.zip"
manifestPath = "config/${this.env.SPACE.toLowerCase()}/manifest.yml"
}
}
}
post {
success {
colourText("info", "Stage: ${env.STAGE_NAME} successful!")
}
failure {
colourText("warn", "Stage: ${env.STAGE_NAME} failed!")
}
}
}
stage('Test: acceptance') {
agent { label 'build.sbt_0-13-13' }
steps {
dir('.') {
git url: "${GITLAB_URL}/AddressIndex/${env.SVC_NAME}.git", credentialsId: 'JenkinsAI__gitlab'
}
script {
env.NODE_STAGE = "Integration Tests"
}
unstash 'compiled'
sh "cp -rv gatling/* server/src/it/resources/uk/gov/ons/gatling/conf"
sh "ls -la server/src/it/resources/uk/gov/ons/gatling/conf"
sh "sbt -DREQUESTS_PER_SECOND=$GATLING_REQUESTS_PER_SECOND -DBASE_URL=$GATLING_GET_ENDPOINT \"project address-index-server\" \"gatling-it:testOnly uk.gov.ons.gatling.simulations.RegistersSimulationClosedModel\""
colourText("success", 'Integration Tests - For Release or Dev environment.')
gatlingArchive()
}
post {
success {
colourText("info", "Stage: ${env.STAGE_NAME} successful!")
}
failure {
colourText("warn", "Stage: ${env.STAGE_NAME} failed!")
}
}
}
}
post {
success {
colourText("success", "All stages complete. Build was successful.")
slackSend(
color: "good",
message: "${env.JOB_NAME} success: ${env.RUN_DISPLAY_URL}"
)
}
unstable {
colourText("warn", "Something went wrong, build finished with result ${currentResult}. This may be caused by failed tests, code violation or in some cases unexpected interrupt.")
slackSend(
color: "danger",
message: "${env.JOB_NAME} unstable: ${env.RUN_DISPLAY_URL}"
)
}
failure {
colourText("warn", "Process failed at: ${env.NODE_STAGE}")
slackSend(
color: "danger",
message: "${env.JOB_NAME} failed at ${env.STAGE_NAME}: ${env.RUN_DISPLAY_URL}"
)
}
}
}