This repository has been archived by the owner on Aug 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Disabled-Jenkinsfile
201 lines (170 loc) · 5.8 KB
/
Disabled-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
pipeline {
agent any
environment {
DEPLOYMENT = readYaml(file: './nais/base/kustomization.yaml')
APPLICATION_NAME = "${DEPLOYMENT.commonLabels.app}"
ZONE = "${DEPLOYMENT.commonAnnotations.zone}"
VERSION = sh(label: 'Get git sha1 as version', script: 'git rev-parse --short HEAD', returnStdout: true).trim()
DOCKER_BUILDKIT = 1
}
stages {
stage('Build') {
// Create tested artifacts that can be used for later stages
environment {
DOCKER_REPO = 'repo.adeo.no:5443'
DOCKER_IMAGE_VERSION = '${DOCKER_REPO}/${APPLICATION_NAME}:${VERSION}'
}
steps {
sh label: 'Install dependencies', script: """
./gradlew assemble
"""
// Should run a set of tests like: unit, functional, component,
// coverage, contract, lint, mutation.
sh label: 'Test code', script: """
./gradlew test
"""
sh label: 'Build artifact', script: """
./gradlew build
"""
withDockerRegistry(
credentialsId: 'repo.adeo.no',
url: "https://${DOCKER_REPO}"
) {
sh label: 'Build and push Docker image', script: """
docker build . --pull -t ${DOCKER_IMAGE_VERSION}
docker push ${DOCKER_IMAGE_VERSION} || true
"""
}
sh label: 'Set image version on base overlay', script: """
sed -i 's/latest/${VERSION}/' ./nais/base/nais.yaml
"""
sh label: 'Prepare dev service contract', script: """
kustomize build ./nais/dev -o ./nais/nais-dev-deploy.yaml && cat ./nais/nais-dev-deploy.yaml
"""
sh label: 'Prepare dev q2 service contract', script: """
kustomize build ./nais/q2 -o ./nais/nais-dev-q2-deploy.yaml && cat ./nais/nais-dev-q2-deploy.yaml
"""
sh label: 'Prepare prod service contract', script: """
kustomize build ./nais/prod -o ./nais/nais-prod-deploy.yaml && cat ./nais/nais-prod-deploy.yaml
"""
}
post {
always {
publishHTML target: [
allowMissing: true,
alwaysLinkToLastBuild: false,
keepAll: true,
reportDir: 'build/reports/tests/test',
reportFiles: 'index.html',
reportName: 'Test coverage'
]
junit 'build/test-results/test/*.xml'
}
}
}
stage('Acceptance testing') {
stages {
stage('Deploy to pre-production') {
when { branch 'master' }
steps {
sh label: 'Deploy with kubectl', script: """
kubectl config use-context dev-${env.ZONE}
kubectl apply -f ./nais/nais-dev-deploy.yaml --wait
kubectl rollout status -w deployment/${APPLICATION_NAME}
"""
archiveArtifacts artifacts: 'nais/nais-dev-deploy.yaml', fingerprint: true
}
}
stage('Run tests') {
// Since these tests usually are quite expensive, running them as
// separate stages allows distributing them on seperate agents
failFast true
parallel {
stage('User Acceptance Tests') {
agent any
when {
beforeAgent true
expression {
sh(
label: 'Does the repository define any UAT tests?',
script: 'test -f ./scripts/test/uat',
returnStatus: true
) == 0
}
}
steps {
sh label: 'User Acceptance Tests', script: """
./scripts/test/uat
"""
}
}
stage('Integration Tests') {
agent any
when {
beforeAgent true
expression {
sh(
label: 'Does the repository define any integration tests?',
script: 'test -f ./scripts/test/integration',
returnStatus: true
) == 0
}
}
steps {
sh label: 'Integration Tests', script: """
./scripts/test/integration || true
"""
}
}
stage('Benchmark Tests') {
agent any
when {
beforeAgent true
expression {
sh(
label: 'Does the repository define any benchmark tests?',
script: 'test -f ./scripts/test/benchmark',
returnStatus: true
) == 0
}
}
steps {
sh label: 'Run benchmark', script: """
./scripts/test/benchmark || true
"""
}
}
}
}
}
}
stage('Deploy q2') {
when { branch 'master' }
steps {
sh label: 'Deploy with kubectl', script: """
kubectl config use-context dev-${env.ZONE}
kubectl apply -n q2 -f ./nais/nais-dev-q2-deploy.yaml --wait && sleep 5
kubectl rollout status -n q2 -w deployment/${APPLICATION_NAME}
"""
archiveArtifacts artifacts: 'nais/nais-dev-q2-deploy.yaml', fingerprint: true
}
}
stage('Deploy') {
when { branch 'master' }
steps {
sh label: 'Deploy with kubectl', script: """
kubectl config use-context prod-${env.ZONE}
kubectl apply -f ./nais/nais-prod-deploy.yaml --wait
kubectl rollout status -w deployment/${APPLICATION_NAME}
"""
archiveArtifacts artifacts: 'nais/nais-prod-deploy.yaml', fingerprint: true
}
}
stage('Release') {
when { branch 'master' }
steps {
sh "echo true"
}
}
}
}