Skip to content

Commit 35cc486

Browse files
committed
Add comments to pr for failures
1 parent 292a209 commit 35cc486

File tree

4 files changed

+74
-43
lines changed

4 files changed

+74
-43
lines changed

Jenkinsfile

Lines changed: 71 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
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+
117
pipeline {
218
agent {
319
label 'docker-multiarch'
@@ -30,7 +46,7 @@ pipeline {
3046
}
3147
steps {
3248
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"
3450
echo 'Building on Master is disabled!'
3551
sh 'exit 1'
3652
}
@@ -45,33 +61,67 @@ pipeline {
4561
steps {
4662
script {
4763
// 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"
5066
}
5167
}
5268
}
5369
}
5470
}
5571
stage('Frontend') {
5672
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+
}
5883
}
59-
/*
6084
post {
6185
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 = ""
6495
}
6596
}
66-
*/
6797
}
6898
stage('Backend') {
6999
steps {
70100
withCredentials([string(credentialsId: 'npm-sentry-dsn', variable: 'SENTRY_DSN')]) {
71101
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+
}
73123
}
74-
sh './scripts/ci/build-backend'
124+
// Build the docker image used for testing below
75125
sh '''docker build --pull --no-cache \\
76126
-t "${IMAGE}:${BRANCH_LOWER}-ci-${BUILD_NUMBER}" \\
77127
-f docker/Dockerfile \\
@@ -83,8 +133,15 @@ pipeline {
83133
}
84134
}
85135
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+
}
86142
success {
87143
archiveArtifacts allowEmptyArchive: false, artifacts: 'bin/*'
144+
shOutput = ""
88145
}
89146
}
90147
}
@@ -152,7 +209,7 @@ pipeline {
152209
withCredentials([string(credentialsId: 'npm-sentry-dsn', variable: 'SENTRY_DSN')]) {
153210
withCredentials([usernamePassword(credentialsId: 'jc21-dockerhub', passwordVariable: 'dpass', usernameVariable: 'duser')]) {
154211
sh 'docker login -u "${duser}" -p "${dpass}"'
155-
sh './scripts/buildx --push ${BUILDX_PUSH_TAGS}'
212+
sh "./scripts/buildx --push ${buildxPushTags}"
156213
// sh './scripts/buildx -o type=local,dest=docker-build'
157214
}
158215
}
@@ -161,33 +218,14 @@ pipeline {
161218
stage('Docs Deploy') {
162219
when {
163220
allOf {
164-
branch 'v3' // TOODO: change to master when ready
221+
branch 'v3' // TODO: change to master when ready
165222
not {
166223
equals expected: 'UNSTABLE', actual: currentBuild.result
167224
}
168225
}
169226
}
170227
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")
191229
}
192230
}
193231
stage('PR Comment') {
@@ -201,7 +239,7 @@ pipeline {
201239
}
202240
steps {
203241
script {
204-
def comment = pullRequest.comment("This is an automated message from CI:\n\nDocker 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)
205243
}
206244
}
207245
}
@@ -235,13 +273,3 @@ pipeline {
235273
}
236274
}
237275
}
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-
}

scripts/ci/build-backend

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/bin/bash
22
set -e
3+
set +x
34

45
IMAGE=jc21/gotools:latest
56

scripts/ci/build-frontend

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/bin/bash
22
set -e
3+
set +x
34

45
BACKEND_ASSETS=backend/embed/assets
56

scripts/ci/test-backend

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/bin/bash
22
set -e
3+
set +x
34

45
IMAGE=jc21/gotools:latest
56

0 commit comments

Comments
 (0)