-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathJenkinsfile
364 lines (360 loc) · 17.5 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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
def build_number = env.BUILD_URL
def customMetrics = [:]
def customMetricsMap = [:]
pipeline{
agent {
label 'ci-pipeline-jenkins-slave'
}
environment {
is_release_version=false
}
stages {
stage('Preparation') {
steps {
script {
customMetricsMap["jenkins_data"] = customMetrics
checkout scm
}
}
}
stage('Install Test Requirements') {
steps {
container("python3") {
sh "pip install -r requirements_test.txt"
}
}
}
stage('Build Atlas Wheels') {
steps {
container("python3") {
sh "./devops/build_scripts/build_all_dev.sh"
}
}
}
stage('Run Atlas Unit test and coverage'){
failFast true
parallel{
stage('Run Unit Tests') {
steps {
container("python3") {
sh "./run_unit_tests.sh"
}
}
}
stage('Run Coverage Tests') {
steps {
container("python3") {
sh "./run_coverage_tests.sh unittest"
}
}
}
}
}
stage('Run Atlas Integration Tests and Prepare for Acceptance Tests'){
parallel{
stage("Integration Tests") {
stages{
stage('Run Integration Tests') {
steps {
container("python3") {
sh './run_integration_tests.sh'
}
}
}
stage('Run Coverage Tests') {
steps {
container("python3") {
sh "./run_coverage_tests.sh integration"
}
}
}
}
}
stage('Install Foundations (container 1)') {
steps {
container("python3-1") {
ws("${WORKSPACE}/atlas/testing") {
sh 'python -m pip install ../dist/*.whl'
}
dir("${WORKSPACE}/foundations_ui") {
sh "yarn install"
}
}
}
}
stage('Install Foundations (container 2)') {
steps {
container("python3-2") {
ws("${WORKSPACE}/atlas/testing") {
sh 'python -m pip install ../dist/*.whl'
}
}
}
}
stage('Install Foundations (container 3)') {
steps {
container("python3-3") {
ws("${WORKSPACE}/atlas/testing") {
sh 'python -m pip install ../dist/*.whl'
}
}
}
}
stage('Install Foundations (container 4)') {
steps {
container("python3-4") {
ws("${WORKSPACE}/atlas/testing") {
sh 'python -m pip install ../dist/*.whl'
}
}
}
}
}
}
stage('Acceptance Tests'){
failFast true
parallel{
stage('Atlas Acceptance Tests') {
steps{
container("python3") {
ws("${WORKSPACE}/atlas/testing") {
sh 'cp -r ../testing/* . || true'
sh """export LOCAL_DOCKER_SCHEDULER_HOST=$ATLAS_LOCAL_SCHEDULER && \
export REDIS_HOST=$ATLAS_LOCAL_SCHEDULER && \
export EXECUTION_REDIS_HOST=localhost && \
export EXECUTION_REDIS_PORT=6379 && \
python -Wi -m unittest -f -v acceptance"""
}
}
}
}
stage('Atlas Acceptance Tests for Stageless Deploys') {
steps {
container("python3-1") {
ws("${WORKSPACE}/atlas/testing") {
sh 'cp -r ../testing/* . || true'
sh 'python -Wi -m unittest -f -v stageless_acceptance'
}
}
}
}
stage('Atlas REST API Acceptance Tests') {
stages{
stage('Atlas REST API Acceptance Tests') {
steps {
container("python3-2") {
dir("${WORKSPACE}"){
sh "./devops/teardown_frontend_dev_atlas.sh || true"
sh "./atlas/foundations_rest_api/src/foundations_rest_api/config/envsubst_local.sh"
sh """export FOUNDATIONS_SCHEDULER_HOST=$ATLAS_LOCAL_SCHEDULER && \
cd atlas/foundations_rest_api/src && \
./foundations_rest_api/config/job_submission_envsubst.sh"""
}
dir("${WORKSPACE}/atlas/foundations_rest_api/src") {
sh """export FOUNDATIONS_HOME=`pwd`/acceptance/v2beta/fixtures/remote_foundations_home && \
export AUTH_CLIENT_CONFIG_PATH=`pwd`/foundations_rest_api/config/auth_client_config.yaml && \
export REDIS_URL=redis://${ATLAS_LOCAL_SCHEDULER}:5556 && \
python -Wi -m unittest -f -v acceptance"""
sh "../../../devops/teardown_frontend_dev_atlas.sh || true"
}
}
}
}
stage('Atlas Auth Acceptance Tests'){
steps {
container("python3-2") {
dir("${WORKSPACE}") {
sh "./devops/teardown_frontend_dev_atlas.sh || true"
sh "./atlas/foundations_rest_api/src/foundations_rest_api/config/envsubst_local.sh"
sh """export AUTH_CLIENT_CONFIG_PATH=`pwd`/atlas/foundations_rest_api/src/foundations_rest_api/config/auth_client_config.yaml && \
export REDIS_PORT=6379 && \
export FOUNDATIONS_SCHEDULER_URL=http://$ATLAS_LOCAL_SCHEDULER:5000 && \
export FOUNDATIONS_HOME=`pwd`/atlas/testing/auth_acceptance/foundations_home && \
python ./devops/startup_atlas_api.py 37722 &"""
}
ws("${WORKSPACE}/atlas/testing") {
sh 'cp -r ../testing/* . || true'
sh """export AUTH_CLIENT_CONFIG_PATH=/home/jenkins/agent/workspace/foundations_master/foundations_rest_api/src/foundations_rest_api/config/auth_client_config.yaml && \
export REDIS_URL=redis://${ATLAS_LOCAL_SCHEDULER}:5556 && \
python -Wi -m unittest -f -v auth_acceptance"""
sh "../../devops/teardown_frontend_dev_atlas.sh || true"
}
}
}
}
}
}
stage('Run Atlas Cypress Tests') {
steps {
container("python3-1") {
// dir("${WORKSPACE}") {
// sh "mkdir -p ~/.foundations/logs"
// sh "./foundations_rest_api/src/foundations_rest_api/config/envsubst_local.sh"
// sh """export FOUNDATIONS_SCHEDULER_URL=http://${ATLAS_LOCAL_SCHEDULER}:5000 && \
// export REDIS_HOST=$ATLAS_LOCAL_SCHEDULER && \
// export REDIS_PORT=5556 && \
// export REDIS_URL=redis://${ATLAS_LOCAL_SCHEDULER}:5556 && \
// export AUTH_CLIENT_CONFIG_PATH=`pwd`/foundations_rest_api/src/foundations_rest_api/config/auth_client_config.yaml && \
// python `pwd`/devops/startup_atlas_api.py 8000 &"""
// sh "`pwd`/devops/build_scripts/helpers/wait_for_url.sh 'http://localhost:8000/api/v2beta/projects' 30"
// sh """export REACT_APP_API_STAGING_URL='http://localhost:8000/api/v2beta/' && \
// cd foundations_ui && \
// BROWSER=none PORT=8082 npm start &"""
// sh "`pwd`/devops/build_scripts/helpers/wait_for_url.sh 'http://localhost:8082' 30"
// sh "sleep 60"
// sh """export CYPRESS_LOCAL_FOUNDATIONS_HOME=`pwd`/foundations_ui/cypress/fixtures/atlas_scheduler/.foundations && \
// export CYPRESS_SCHEDULER_IP=$ATLAS_LOCAL_SCHEDULER && \
// export CYPRESS_SCHEDULER_FOUNDATIONS_HOME=$REMOTE_FOUNDATIONS_HOME && \
// export CYPRESS_SCHEDULER_REDIS_PORT=5556 && \
// export CYPRESS_GUI_HOST=localhost && \
// export CYPRESS_GUI_PORT=8082 && export CYPRESS_ATLAS_EDITION=CE && \
// export CYPRESS_PROXY_PORT=5558 && \
// export CYPRESS_REST_API_HOST=localhost && \
// export CYPRESS_REST_API_PORT=8000 && \
// export CYPRESS_FAIL_FAST=true && \
// export AUTH_CLIENT_CONFIG_PATH=`pwd`/foundations_rest_api/src/foundations_rest_api/config/auth_client_config.yaml && \
// cd foundations_ui && \
// npm run cy:run --"""
// }
}
}
}
}
}
stage('UI Test for Atlas'){
parallel{
stage('UI Test for Atlas') {
stages {
stage('Install dependencies for Atlas UI') {
steps {
container("python3") {
ws("${WORKSPACE}/foundations_ui/") {
sh "yarn cache clean"
sh "yarn install"
}
}
}
}
stage('Check for Atlas linting ') {
steps {
container("python3") {
ws("${WORKSPACE}/foundations_ui/") {
sh "node_modules/.bin/eslint ."
}
}
}
}
}
}
}
}
stage('Upload Coverage results to Jenkins') {
steps {
container("python3") {
sh "tar -czvf coverage.tar.gz atlas/coverage_results"
archiveArtifacts artifacts: 'coverage.tar.gz'
}
}
}
stage('Set Deployment to be True') {
when { tag "*.*" }
steps {
echo 'Deploying only because this commit is tagged...'
script {
env.is_release_version=true
}
}
}
stage("Calculate Recovery Metrics") {
steps {
script {
def last_build = currentBuild.getPreviousBuild()
def last_failed_build
def current_time = System.currentTimeMillis()
while(last_build != null && last_build.result == "FAILURE") {
last_failed_build = last_build
last_build = last_build.getPreviousBuild()
}
if(last_failed_build != null) {
time_to_recovery = current_time - last_failed_build.getTimeInMillis()
customMetrics["time_to_recovery"] = time_to_recovery
}
}
}
}
stage('Trigger Build Artifacts for Atlas Pipeline') {
when { branch 'master' }
steps {
container("python3") {
script {
echo "Triggering job for building Atlas Artifacts"
f9s_commit_hash = sh(script: "echo \$(git log --pretty=format:'%h' -n 1)", returnStdout: true).trim()
println("Attempting to trigger pipeline with version of ${f9s_commit_hash}")
build job: "build-artifacts-atlas", wait: false, parameters: [
[$class: 'StringParameterValue', name: 'f9s_commit_hash', value: "${f9s_commit_hash}"],
[$class: 'BooleanParameterValue', name: 'is_release_version', value: env.is_release_version]
]
}
}
}
}
stage('Trigger Build Artifacts for Atlas Pipeline (For Release)') {
when { tag "*.*" }
steps {
container("python3") {
script {
echo "Triggering job for building Atlas Artifacts"
f9s_commit_hash = sh(script: "echo \$(git log --pretty=format:'%h' -n 1)", returnStdout: true).trim()
println("Attempting to trigger pipeline with version of ${f9s_commit_hash}")
build job: "build-artifacts-atlas", wait: false, parameters: [
[$class: 'StringParameterValue', name: 'f9s_commit_hash', value: "${f9s_commit_hash}"],
[$class: 'BooleanParameterValue', name: 'is_release_version', value: env.is_release_version]
]
}
}
}
}
}
post {
always {
script {
customMetricsMap["jenkins_data"] = customMetrics
}
influxDbPublisher selectedTarget: 'foundations', customPrefix: 'foundations', customProjectName: 'foundations', jenkinsEnvParameterField: '', jenkinsEnvParameterTag: '', customDataMap: customMetricsMap
}
failure {
script {
def output_logs = String.join('\n', currentBuild.rawBuild.getLog(200))
def attachments = [
[
pretext: '@channel Build failed for `' + env.JOB_NAME + '` please visit ' + env.BUILD_URL + ' for more details.',
text: output_logs,
fallback: '@channel Build failed for `' + env.JOB_NAME + '` please visit ' + env.BUILD_URL + ' for more details.',
color: '#FF0000'
]
]
slackSend(channel: '#dessa-atlas-builds', attachments: attachments)
}
}
success {
slackSend color: '#00FF00', message: 'Build succeeded for `' + env.JOB_NAME + '` please visit ' + env.BUILD_URL + ' for more details.'
}
cleanup {
container("python3-1") {
sh "`pwd`/devops/teardown_frontend_dev_atlas.sh || true"
sh "kill -9 `lsof -i:8000 -t` || true"
sh "kill -9 `lsof -i:8082 -t` || true"
}
container("python3-2") {
sh "kill -9 `lsof -i:37722 -t` || true"
}
container("python3-3") {
sh "kill -9 `lsof -i:8081 -t` || true"
}
container('python3') {
sh 'rm -rf ci'
sh 'git clean -fdx'
}
}
}
}