-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathJenkinsfile
115 lines (88 loc) · 3.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
#!/usr/bin/env groovy
@Library("github.com/RedHatInsights/insights-pipeline-lib@v3")
NS = 'remediations-ci'
TESTNS = 'remediations-pr'
def notify(subject, body, color) {
message = subject
if (body != null) {
message += " | ${body}"
}
slackSend message: message, color: color, channel: '#remediations'
}
def notifyOnFailure(Closure step) {
try {
step()
} catch (e) {
notify("@Alec Cohan [${env.JOB_NAME.split('/')[-1]}] Build failed", "See ${env.BUILD_URL}console", "danger")
throw e
}
}
node {
notifyOnFailure {
notify("[${env.JOB_NAME.split('/')[-1]}] Build started", null, "#439FE0")
env.NODEJS_HOME = "${tool 'node-10'}"
env.PATH="${env.NODEJS_HOME}/bin:${env.PATH}"
checkout scm
def utils = load "./build/utils.groovy"
def deploy = { namespace ->
timeout (5) {
openshift.withProject(namespace) {
try {
sh "oc scale --replicas=0 --namespace=${namespace} dc/remediations"
// need to bring down consumer also so that the database can be recreated
sh "oc scale --replicas=0 --namespace=${namespace} dc/remediations-consumer"
utils.waitFor(namespace, 0, 'remediations')
utils.waitFor(namespace, 0, 'remediations-consumer')
def dc = openshift.selector('dc', 'remediations')
dc.rollout().latest()
dc.rollout().status() // wait for rollout to reach desired replica count
// this recreates database and runs migrations
} finally {
sh "oc scale --replicas=1 --namespace=${namespace} dc/remediations"
utils.waitFor(namespace, 1, 'remediations')
sh "oc scale --replicas=1 --namespace=${namespace} dc/remediations-consumer"
utils.waitFor(namespace, 1, 'remediations-consumer')
}
}
}
}
sh 'git rev-parse HEAD'
stage('build') {
sh 'npm ci'
}
stage('cross-check ssg template validator') {
sh "node src/validateTemplate.js src/connectors/ssg/mock/standard/*"
}
openshift.withCluster() {
utils.withScaledEnv(TESTNS) {
env.DB_HOST="postgres.${TESTNS}.svc"
env.DB_DATABASE='remediationstest'
stage('verify') {
env.VMAAS_IMPL='mock'
sh 'npm run verify'
}
stage('migration') {
sh 'npm run db:migrate'
sh 'npm run db:migrate:undo:all'
}
stage('contract tests') {
env.SSG_IMPL='impl'
env.SSG_HOST="http://playbooks-ssg.${NS}.svc:8080"
sh 'npm run test'
}
}
stage('build image') {
timeout (10) {
openshift.withProject('buildfactory') {
def build = openshift.selector('bc', 'remediations').startBuild()
build.logs('-f')
}
}
}
stage('deploy to CI') {
deploy('remediations-ci')
}
notify("[${env.JOB_NAME.split('/')[-1]}] Build finished", null, "good")
}
}
}