1
+ import groovy.transform.Field
2
+
3
+ @Field
4
+ def shOutput = " "
5
+ def buildxPushTags = " "
6
+
7
+ def getVersion () {
8
+ ver = sh(script : ' cat .version' , returnStdout : true )
9
+ return ver. trim()
10
+ }
11
+
12
+ def getCommit () {
13
+ ver = sh(script : ' git log -n 1 --format=%h' , returnStdout : true )
14
+ return ver. trim()
15
+ }
16
+
1
17
pipeline {
2
18
agent {
3
19
label ' docker-multiarch'
@@ -30,7 +46,7 @@ pipeline {
30
46
}
31
47
steps {
32
48
script {
33
- env . BUILDX_PUSH_TAGS = " -t docker.io/${ DOCKER_ORG} /${ IMAGE} :${ BUILD_VERSION} -t docker.io/${ DOCKER_ORG} /${ IMAGE} :${ MAJOR_VERSION} -t docker.io/${ DOCKER_ORG} /${ IMAGE} :latest"
49
+ buildxPushTags = " -t docker.io/${ DOCKER_ORG} /${ IMAGE} :${ BUILD_VERSION} -t docker.io/${ DOCKER_ORG} /${ IMAGE} :${ MAJOR_VERSION} -t docker.io/${ DOCKER_ORG} /${ IMAGE} :latest"
34
50
echo ' Building on Master is disabled!'
35
51
sh ' exit 1'
36
52
}
@@ -45,33 +61,67 @@ pipeline {
45
61
steps {
46
62
script {
47
63
// Defaults to the Branch name, which is applies to all branches AND pr's
48
- // env.BUILDX_PUSH_TAGS = "-t docker.io/jc21/${IMAGE}:github-${BRANCH_LOWER}"
49
- env . BUILDX_PUSH_TAGS = " -t docker.io/${ DOCKER_ORG} /${ IMAGE} :v3"
64
+ // buildxPushTags = "-t docker.io/jc21/${IMAGE}:github-${BRANCH_LOWER}"
65
+ buildxPushTags = " -t docker.io/${ DOCKER_ORG} /${ IMAGE} :v3"
50
66
}
51
67
}
52
68
}
53
69
}
54
70
}
55
71
stage(' Frontend' ) {
56
72
steps {
57
- sh ' ./scripts/ci/build-frontend'
73
+ script {
74
+ def shStatusCode = sh(label : ' build-frontend' , returnStatus : true , script : '''
75
+ set -e
76
+ ./scripts/ci/build-frontend > ${WORKSPACE}/tmp-sh-build 2>&1
77
+ ''' )
78
+ shOutput = readFile " ${ env.WORKSPACE} /tmp-sh-build"
79
+ if (shStatusCode != 0 ) {
80
+ error " ${ shOutput} "
81
+ }
82
+ }
58
83
}
59
- /*
60
84
post {
61
85
always {
62
- junit 'frontend/eslint.xml'
63
- junit 'frontend/junit.xml'
86
+ sh ' rm -f ${WORKSPACE}/tmp-sh-build'
87
+ // junit 'frontend/eslint.xml'
88
+ // junit 'frontend/junit.xml'
89
+ }
90
+ failure {
91
+ npmGithubPrComment(" CI Error:\n\n ```\n ${ shOutput} \n ```" , true )
92
+ }
93
+ success {
94
+ shOutput = " "
64
95
}
65
96
}
66
- */
67
97
}
68
98
stage(' Backend' ) {
69
99
steps {
70
100
withCredentials([string(credentialsId : ' npm-sentry-dsn' , variable : ' SENTRY_DSN' )]) {
71
101
withCredentials([usernamePassword(credentialsId : ' oss-index-token' , passwordVariable : ' NANCY_TOKEN' , usernameVariable : ' NANCY_USER' )]) {
72
- sh ' ./scripts/ci/test-backend'
102
+ script {
103
+ def shStatusCode = sh(label : ' test-backend' , returnStatus : true , script : '''
104
+ set -e
105
+ ./scripts/ci/test-backend > ${WORKSPACE}/tmp-sh-build 2>&1
106
+ ''' )
107
+ shOutput = readFile " ${ env.WORKSPACE} /tmp-sh-build"
108
+ if (shStatusCode != 0 ) {
109
+ error " ${ shOutput} "
110
+ }
111
+ }
112
+ }
113
+ // Build all the golang binaries
114
+ script {
115
+ def shStatusCode = sh(label : ' build-backend' , returnStatus : true , script : '''
116
+ set -e
117
+ ./scripts/ci/build-backend > ${WORKSPACE}/tmp-sh-build 2>&1
118
+ ''' )
119
+ shOutput = readFile " ${ env.WORKSPACE} /tmp-sh-build"
120
+ if (shStatusCode != 0 ) {
121
+ error " ${ shOutput} "
122
+ }
73
123
}
74
- sh ' ./scripts/ci/build-backend '
124
+ // Build the docker image used for testing below
75
125
sh ''' docker build --pull --no-cache \\
76
126
-t "${IMAGE}:${BRANCH_LOWER}-ci-${BUILD_NUMBER}" \\
77
127
-f docker/Dockerfile \\
@@ -83,8 +133,15 @@ pipeline {
83
133
}
84
134
}
85
135
post {
136
+ always {
137
+ sh ' rm -f ${WORKSPACE}/tmp-sh-build'
138
+ }
139
+ failure {
140
+ npmGithubPrComment(" CI Error:\n\n ```\n ${ shOutput} \n ```" , true )
141
+ }
86
142
success {
87
143
archiveArtifacts allowEmptyArchive : false , artifacts : ' bin/*'
144
+ shOutput = " "
88
145
}
89
146
}
90
147
}
@@ -152,7 +209,7 @@ pipeline {
152
209
withCredentials([string(credentialsId : ' npm-sentry-dsn' , variable : ' SENTRY_DSN' )]) {
153
210
withCredentials([usernamePassword(credentialsId : ' jc21-dockerhub' , passwordVariable : ' dpass' , usernameVariable : ' duser' )]) {
154
211
sh ' docker login -u "${duser}" -p "${dpass}"'
155
- sh ' ./scripts/buildx --push ${BUILDX_PUSH_TAGS} '
212
+ sh " ./scripts/buildx --push ${ buildxPushTags } "
156
213
// sh './scripts/buildx -o type=local,dest=docker-build'
157
214
}
158
215
}
@@ -161,33 +218,14 @@ pipeline {
161
218
stage(' Docs Deploy' ) {
162
219
when {
163
220
allOf {
164
- branch ' v3' // TOODO : change to master when ready
221
+ branch ' v3' // TODO : change to master when ready
165
222
not {
166
223
equals expected : ' UNSTABLE' , actual : currentBuild. result
167
224
}
168
225
}
169
226
}
170
227
steps {
171
- withCredentials([[$class : ' AmazonWebServicesCredentialsBinding' , accessKeyVariable : ' AWS_ACCESS_KEY_ID' , credentialsId : ' npm-s3-docs' , secretKeyVariable : ' AWS_SECRET_ACCESS_KEY' ]]) {
172
- sh """ docker run --rm \\
173
- --name \$ {COMPOSE_PROJECT_NAME}-docs-upload \\
174
- -e S3_BUCKET=$DOCS_BUCKET \\
175
- -e AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID \\
176
- -e AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY \\
177
- -v \$ (pwd):/app \\
178
- -w /app \\
179
- jc21/ci-tools \\
180
- scripts/docs-upload /app/docs/.vuepress/dist/
181
- """
182
-
183
- sh """ docker run --rm \\
184
- --name \$ {COMPOSE_PROJECT_NAME}-docs-invalidate \\
185
- -e AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID \\
186
- -e AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY \\
187
- jc21/ci-tools \\
188
- aws cloudfront create-invalidation --distribution-id $DOCS_CDN --paths '/*'
189
- """
190
- }
228
+ npmDocsRelease(" $DOCS_BUCKET " , " $DOCS_CDN " )
191
229
}
192
230
}
193
231
stage(' PR Comment' ) {
@@ -201,7 +239,7 @@ pipeline {
201
239
}
202
240
steps {
203
241
script {
204
- def comment = pullRequest . comment( " This is an automated message from CI: \n\n Docker Image for build ${ BUILD_NUMBER} is available on [DockerHub](https://cloud.docker.com/repository/docker/${ DOCKER_ORG} /${ IMAGE} ) as `${ DOCKER_ORG} /${ IMAGE} :github-${ BRANCH_LOWER} `\n\n **Note:** ensure you backup your NPM instance before testing this PR image! Especially if this PR contains database changes." )
242
+ npmGithubPrComment( " Docker Image for build ${ BUILD_NUMBER} is available on [DockerHub](https://cloud.docker.com/repository/docker/${ DOCKER_ORG} /${ IMAGE} ) as `${ DOCKER_ORG} /${ IMAGE} :github-${ BRANCH_LOWER} `\n\n **Note:** ensure you backup your NPM instance before testing this PR image! Especially if this PR contains database changes." , true )
205
243
}
206
244
}
207
245
}
@@ -235,13 +273,3 @@ pipeline {
235
273
}
236
274
}
237
275
}
238
-
239
- def getVersion () {
240
- ver = sh(script : ' cat .version' , returnStdout : true )
241
- return ver. trim()
242
- }
243
-
244
- def getCommit () {
245
- ver = sh(script : ' git log -n 1 --format=%h' , returnStdout : true )
246
- return ver. trim()
247
- }
0 commit comments