1
- def commit = " UNKNOWN"
2
- def version = " UNKNOWN"
3
- def chartversion = " 3.1.0"
1
+ def chartversion = " 3.1.1"
4
2
5
3
pipeline {
6
4
agent {
29
27
volumeMounts:
30
28
- name: docker-graph-storage
31
29
mountPath: /var/lib/docker
32
- - name: helm
33
- image: alpine/helm:2.12.3
34
- command:
35
- - cat
36
- tty: true
37
30
- name: docker
38
31
image: docker:18-git
39
32
tty: true
@@ -50,17 +43,45 @@ spec:
50
43
"""
51
44
}
52
45
}
46
+
47
+ environment {
48
+ gitHubRegistry = ' ghcr.io'
49
+ gitHubRepo = ' overture-stack/ego'
50
+ gitHubImageName = " ${ gitHubRegistry} /${ gitHubRepo} "
51
+ dockerHubImageName = ' overture/ego'
52
+ DEPLOY_TO_DEV = false
53
+ PUBLISH_IMAGE = false
54
+
55
+ commit = sh(
56
+ returnStdout : true ,
57
+ script : ' git describe --always'
58
+ ). trim()
59
+
60
+ version = readMavenPom(). getVersion()
61
+ slackNotificationsUrl = credentials(' OvertureSlackJenkinsWebhookURL' )
62
+
63
+ }
64
+
65
+ parameters {
66
+ booleanParam(
67
+ name : ' DEPLOY_TO_DEV' ,
68
+ defaultValue : " ${ env.DEPLOY_TO_DEV} " ,
69
+ description : ' Deploys your branch to argo-dev'
70
+ )
71
+ booleanParam(
72
+ name : ' PUBLISH_IMAGE' ,
73
+ defaultValue : " ${ env.PUBLISH_IMAGE ?: params.DEPLOY_TO_DEV} " ,
74
+ description : ' Publishes an image with {git commit} tag'
75
+ )
76
+ }
77
+
78
+ options {
79
+ timeout(time : 30 , unit : ' MINUTES' )
80
+ timestamps()
81
+ }
82
+
83
+
53
84
stages {
54
- stage(' Prepare' ) {
55
- steps {
56
- script {
57
- commit = sh(returnStdout : true , script : ' git describe --always' ). trim()
58
- }
59
- script {
60
- version = readMavenPom(). getVersion()
61
- }
62
- }
63
- }
64
85
stage(' Test' ) {
65
86
environment {
66
87
SELENIUM_TEST_TYPE = ' BROWSERSTACK'
@@ -77,10 +98,19 @@ spec:
77
98
}
78
99
}
79
100
}
101
+
102
+ stage(' Build image' ) {
103
+ steps {
104
+ container(' docker' ) {
105
+ sh " docker build --network=host -f Dockerfile . -t ${ gitHubImageName} :${ commit} "
106
+ }
107
+ }
108
+ }
109
+
80
110
stage(' Build Artifact & Publish' ) {
81
111
when {
82
112
anyOf {
83
- branch " master "
113
+ branch " main "
84
114
branch " develop"
85
115
}
86
116
}
@@ -93,45 +123,113 @@ spec:
93
123
}
94
124
}
95
125
}
96
- stage(' Build & Publish Develop' ) {
126
+
127
+ stage(' Publish images' ) {
97
128
when {
98
- branch " develop"
129
+ anyOf {
130
+ branch ' develop'
131
+ branch ' main'
132
+ expression { return params. PUBLISH_IMAGE }
133
+ }
99
134
}
100
135
steps {
101
136
container(' docker' ) {
102
- withCredentials([usernamePassword(credentialsId :' OvertureDockerHub' , usernameVariable : ' USERNAME' , passwordVariable : ' PASSWORD' )]) {
103
- sh ' docker login -u $USERNAME -p $PASSWORD'
137
+ withCredentials([usernamePassword(
138
+ credentialsId :' OvertureBioGithub' ,
139
+ passwordVariable : ' PASSWORD' ,
140
+ usernameVariable : ' USERNAME'
141
+ )]) {
142
+ sh " docker login ${ gitHubRegistry} -u $USERNAME -p $PASSWORD "
143
+
144
+ script {
145
+ if (env. BRANCH_NAME ==~ ' main' ) { // push edge and commit tags
146
+ sh " docker tag ${ gitHubImageName} :${ commit} ${ gitHubImageName} :${ version} "
147
+ sh " docker push ${ gitHubImageName} :${ version} "
148
+
149
+ sh " docker tag ${ gitHubImageName} :${ commit} ${ gitHubImageName} :latest"
150
+ sh " docker push ${ gitHubImageName} :latest"
151
+ } else { // push commit tag
152
+ sh " docker push ${ gitHubImageName} :${ commit} "
153
+ }
154
+
155
+ if (env. BRANCH_NAME ==~ ' develop' ) { // push edge tag
156
+ sh " docker tag ${ gitHubImageName} :${ commit} ${ gitHubImageName} :edge"
157
+ sh " docker push ${ gitHubImageName} :edge"
158
+ }
159
+ }
160
+ }
161
+ }
162
+ container(' docker' ) {
163
+ withCredentials([usernamePassword(
164
+ credentialsId :' OvertureDockerHub' ,
165
+ passwordVariable : ' PASSWORD' ,
166
+ usernameVariable : ' USERNAME'
167
+ )]) {
168
+ sh " docker login -u $USERNAME -p $PASSWORD "
169
+
170
+ script {
171
+ if (env. BRANCH_NAME ==~ ' main' ) { // push edge and commit tags
172
+ sh " docker tag ${ gitHubImageName} :${ commit} ${ dockerHubImageName} :${ version} "
173
+ sh " docker push ${ dockerHubImageName} :${ version} "
174
+
175
+ sh " docker tag ${ gitHubImageName} :${ commit} ${ dockerHubImageName} :latest"
176
+ sh " docker push ${ dockerHubImageName} :latest"
177
+ } else { // push commit tag
178
+ sh " docker tag ${ gitHubImageName} :${ commit} ${ dockerHubImageName} :${ commit} "
179
+ sh " docker push ${ dockerHubImageName} :${ commit} "
180
+ }
181
+
182
+ if (env. BRANCH_NAME ==~ ' develop' ) { // push edge tag
183
+ sh " docker tag ${ gitHubImageName} :${ commit} ${ dockerHubImageName} :edge"
184
+ sh " docker push ${ dockerHubImageName} :edge"
185
+ }
186
+ }
104
187
}
105
- sh " docker build --network=host -f Dockerfile . -t overture/ego:edge -t overture/ego:${ commit} "
106
- sh " docker push overture/ego:${ commit} "
107
- sh " docker push overture/ego:edge"
108
188
}
109
189
}
110
190
}
111
191
112
- stage(' Release & tag' ) {
113
- when {
114
- branch " master"
115
- }
116
- steps {
117
- container(' docker' ) {
118
- withCredentials([usernamePassword(credentialsId : ' OvertureBioGithub' , passwordVariable : ' GIT_PASSWORD' , usernameVariable : ' GIT_USERNAME' )]) {
119
- sh " git tag ${ version} "
120
- sh " git push https://${ GIT_USERNAME} :${ GIT_PASSWORD} @github.com/overture-stack/ego --tags"
121
- }
122
- withCredentials([usernamePassword(credentialsId :' OvertureDockerHub' , usernameVariable : ' USERNAME' , passwordVariable : ' PASSWORD' )]) {
123
- sh ' docker login -u $USERNAME -p $PASSWORD'
192
+ stage(' Publish tag to github' ) {
193
+ when {
194
+ branch ' main'
195
+ }
196
+ steps {
197
+ container(' node' ) {
198
+ withCredentials([
199
+ usernamePassword(
200
+ credentialsId : ' OvertureBioGithub' ,
201
+ passwordVariable : ' GIT_PASSWORD' ,
202
+ usernameVariable : ' GIT_USERNAME'
203
+ ),
204
+ ]) {
205
+ script {
206
+ // we still want to run the platform deploy even if this fails, hence try-catch
207
+ try {
208
+ sh " git tag ${ version} "
209
+ sh " git push https://${ GIT_USERNAME} :${ GIT_PASSWORD} @github.com/${ gitHubRepo} --tags"
210
+ sh " curl \
211
+ -X POST \
212
+ -H 'Content-type: application/json' \
213
+ --data '{ \
214
+ \" text\" :\" New ${ gitHubRepo} published succesfully: v.${ version} \
215
+ \n [Build ${ env.BUILD_NUMBER} ] (${ env.BUILD_URL} )\" \
216
+ }' \
217
+ ${ slackNotificationsUrl} "
218
+ } catch (err) {
219
+ echo ' There was an error while publishing packages'
220
+ }
221
+ }
124
222
}
125
- sh " docker build --network=host -f Dockerfile . -t overture/ego:latest -t overture/ego:${ version} "
126
- sh " docker push overture/ego:${ version} "
127
- sh " docker push overture/ego:latest"
128
223
}
129
224
}
130
225
}
131
226
132
227
stage(' Deploy to Overture QA' ) {
133
228
when {
134
- branch " develop"
229
+ anyOf {
230
+ branch ' develop'
231
+ expression { return params. DEPLOY_TO_DEV }
232
+ }
135
233
}
136
234
steps {
137
235
build(job : " /Overture.bio/provision/helm" , parameters : [
@@ -148,7 +246,9 @@ spec:
148
246
149
247
stage(' Deploy to Overture Staging' ) {
150
248
when {
151
- branch " master"
249
+ anyOf {
250
+ branch ' main'
251
+ }
152
252
}
153
253
steps {
154
254
build(job : " /Overture.bio/provision/helm" , parameters : [
@@ -162,6 +262,52 @@ spec:
162
262
])
163
263
}
164
264
}
265
+ }
266
+
267
+ post {
268
+ fixed {
269
+ script {
270
+ if (env. BRANCH_NAME ==~ / (develop|main|test\S *)/ ) {
271
+ sh " curl \
272
+ -X POST \
273
+ -H 'Content-type: application/json' \
274
+ --data '{ \
275
+ \" text\" :\" Build Fixed: ${ env.JOB_NAME} #${ commit} \
276
+ \n [Build ${ env.BUILD_NUMBER} ] (${ env.BUILD_URL} )\" \
277
+ }' \
278
+ ${ slackNotificationsUrl} "
279
+ }
280
+ }
281
+ }
165
282
283
+ success {
284
+ script {
285
+ if (env. BRANCH_NAME ==~ / (test\S *)/ ) {
286
+ sh " curl \
287
+ -X POST \
288
+ -H 'Content-type: application/json' \
289
+ --data '{ \
290
+ \" text\" :\" Build tested: ${ env.JOB_NAME} #${ commit} \
291
+ \n [Build ${ env.BUILD_NUMBER} ] (${ env.BUILD_URL} )\" \
292
+ }' \
293
+ ${ slackNotificationsUrl} "
294
+ }
295
+ }
296
+ }
297
+
298
+ unsuccessful {
299
+ script {
300
+ if (env. BRANCH_NAME ==~ / (develop|main|test\S *)/ ) {
301
+ sh " curl \
302
+ -X POST \
303
+ -H 'Content-type: application/json' \
304
+ --data '{ \
305
+ \" text\" :\" Build Failed: ${ env.JOB_NAME} #${ commit} \
306
+ \n [Build ${ env.BUILD_NUMBER} ] (${ env.BUILD_URL} )\" \
307
+ }' \
308
+ ${ slackNotificationsUrl} "
309
+ }
310
+ }
311
+ }
166
312
}
167
313
}
0 commit comments