-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
275 lines (233 loc) · 9.68 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
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
270
271
272
273
274
275
#!groovy
// Deployment units for this code repo
def deploymentUnits = [
'avscanner'
]
pipeline {
agent {
label 'hamlet-latest'
}
options {
timestamps ()
buildDiscarder(
logRotator(
numToKeepStr: '10'
)
)
disableConcurrentBuilds()
durabilityHint('PERFORMANCE_OPTIMIZED')
parallelsAlwaysFailFast()
skipDefaultCheckout()
quietPeriod 60
}
environment {
properties_file = '/var/opt/properties/biosecurity.properties'
slack_channel = '#bio-integration'
}
stages {
stage('Testing') {
environment {
COMPOSE_PROJECT_NAME = "${BUILD_TAG}"
COMPOSE_FILE="docker-compose.yml:docker-compose-ci.yml"
}
stages {
stage('Setup') {
steps {
dir('test') {
script {
def codeRepo = checkout scm
env["GIT_COMMIT"] = codeRepo.GIT_COMMIT
}
sh '''#!/bin/bash
mkdir --parents ./minio/data/archive
mkdir --parents ./minio/data/quarantine
mkdir --parents ./minio/data/unprocessed
'''
}
}
}
stage('Run Testing') {
steps {
dir('test') {
// running tests using entrypoint-ci.sh as entrypoint script, see docker-compose-ci.yml
sh '''#!/bin/bash
# Testing
docker-compose --no-ansi up --build --remove-orphans --exit-code-from processor
'''
}
}
post {
always {
dir('test'){
script {
def summary = junit 'src/test-report.xml'
env['CHECK_STATUS'] = "FAILURE"
env['TOTAL_COUNT'] = summary.totalCount
env['FAIL_COUNT'] = summary.failCount
env['SKIP_COUNT'] = summary.skipCount
env['PASS_COUNT'] = summary.passCount
env['CHECK_CONCLUSION'] = "SUCCESS"
if (env.FAIL_COUNT.toInteger() != 0) {
env['CHECK_CONCLUSION'] = "FAILURE"
}
}
publishChecks name: 'Tests', conclusion: "${env.CHECK_CONCLUSION}", title: "Test Summary - ${env.TOTAL_COUNT}, Failures: ${env.FAIL_COUNT}, Skipped: ${env.SKIP_COUNT}, Passed: ${env.PASS_COUNT}", summary: 'test results', text: "Test Summary - ${env.TOTAL_COUNT}, Failures: ${env.FAIL_COUNT}, Skipped: ${env.SKIP_COUNT}, Passed: ${env.PASS_COUNT}"
publishCoverage adapters: [coberturaAdapter('src/coverage.xml')]
}
}
}
}
stage('Style') {
steps {
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
dir('test') {
sh '''#!/bin/bash
flake8 --output-file=flake8.txt
'''
}
}
}
post {
always {
dir('test') {
recordIssues enabledForFailure: true, qualityGates: [[threshold: 1, type: 'TOTAL', unstable: false]], tool: flake8(pattern: 'flake8.txt')
}
}
}
}
}
post {
failure {
slackSend (
message: "*Failure* | <${BUILD_URL}|${JOB_NAME}> \n Testing stage",
channel: "${env["slack_channel"]}",
color: "#D20F2A"
)
}
cleanup {
dir('test') {
sh '''#!/bin/bash
if [[ -n "${COMPOSE_FILE}" ]]; then
docker-compose down --rmi local -v --remove-orphans
fi
'''
}
}
}
}
stage('continuous deploy') {
when {
anyOf {
branch 'master'
branch 'cd_*'
}
}
environment {
ENVIRONMENT = 'integration'
PRODUCT_INFRASTRUCTURE_REFERENCE = 'master'
PRODUCT_CONFIG_REFERENCE = 'master'
GENERATION_CONTEXT_DEFINED = ''
DEPLOYMENT_UNITS = "${deploymentUnits.join(",")}"
IMAGE_FORMAT = 'docker'
BUILD_PATH = ''
DOCKER_CONTEXT_DIR = 'build'
BUILD_SRC_DIR = ''
DOCKER_FILE = "build/devops/docker/Dockerfile"
product_cmdb = 'https://github.com/gs-dawr/biosecurity-cmdb'
GITHUB_CREDENTIALS = credentials('github')
}
steps {
// Product Setup
dir('.hamlet/product') {
git(
url: "${env["product_cmdb"]}",
credentialsId: 'github',
changelog: false,
poll: false
)
// Load in Properties files
script {
def productProperties = readProperties interpolate: true, file: "${env.properties_file}";
productProperties.each{ k, v -> env["${k}"] ="${v}" }
}
}
dir('build') {
checkout scm
}
sh '''#!/bin/bash
${AUTOMATION_BASE_DIR}/setContext.sh
'''
script {
def contextProperties = readProperties interpolate: true, file: "${WORKSPACE}/context.properties";
contextProperties.each{ k, v -> env["${k}"] ="${v}" }
}
sh '''#!/bin/bash
${AUTOMATION_DIR}/constructTree.sh
'''
script {
def contextProperties = readProperties interpolate: true, file: "${WORKSPACE}/context.properties";
contextProperties.each{ k, v -> env["${k}"] ="${v}" }
}
sh '''#!/bin/bash
${AUTOMATION_DIR}/manageImages.sh
'''
script {
def contextProperties = readProperties interpolate: true, file: "${WORKSPACE}/context.properties";
contextProperties.each{ k, v -> env["${k}"] ="${v}" }
}
build job: "../../deploy/${env["ENVIRONMENT"]}-deploy", wait: false, parameters: [
string(name: 'DEPLOYMENT_UNITS', value: "${env["DEPLOYMENT_UNITS"]}" ),
string(name: 'GIT_COMMIT', value: "${env["GIT_COMMIT"]}"),
string(name: 'IMAGE_FORMATS', value: "${env["IMAGE_FORMAT"]}" )
]
}
post {
success {
slackSend (
message: "*Success* | <${BUILD_URL}|${JOB_NAME}> \n CD deployment started",
channel: "${env["slack_channel"]}",
color: "#50C878"
)
}
}
}
stage('release') {
when {
buildingTag()
}
environment {
ENVIRONMENT = 'production'
DEPLOYMENT_UNITS = "${deploymentUnits.join(",")}"
}
steps {
script {
releaseTag = env["TAG_NAME"] ?: env["GIT_COMMIT"].take(7)
prepareUnits = ""
(env.DEPLOYMENT_UNITS).split(",").each{ i -> prepareUnits = prepareUnits + "${i}!${env["GIT_COMMIT"]}\n" }
build job: "../../deploy/${env["ENVIRONMENT"]}-prepare", wait: true, parameters: [
string(name: 'DEPLOYMENT_UNITS', value: "${prepareUnits}" ),
string(name: 'RELEASE_IDENTIFIER', value: "${releaseTag}_${currentBuild.timeInMillis}"),
]
build job: "../../deploy/${env["ENVIRONMENT"]}-deploy", wait: true, parameters: [
string(name: 'DEPLOYMENT_UNITS', value: "${env["DEPLOYMENT_UNITS"]}" ),
string(name: 'RELEASE_IDENTIFIER', value: "${releaseTag}_${currentBuild.timeInMillis}"),
]
}
}
post {
success {
slackSend (
message: "*Success* | <${BUILD_URL}|${JOB_NAME}> \n Release to ${env["ENVIRONMENT"]} completed",
channel: "${env["slack_channel"]}",
color: "#50C878"
)
}
}
}
}
post {
cleanup {
cleanWs()
}
}
}