1+ import  groovy.transform.Field 
2+ 
3+ @Field 
4+ def  shOutput =  " " 
5+ def  buildxPushTags =  " " 
6+ 
17pipeline {
28	agent {
39		label ' docker-multiarch' 
@@ -16,6 +22,8 @@ pipeline {
1622		COMPOSE_FILE                =  ' docker/docker-compose.ci.yml' 
1723		COMPOSE_INTERACTIVE_NO_CLI  =  1 
1824		BUILDX_NAME                 =  " ${ COMPOSE_PROJECT_NAME} " 
25+ 		DOCS_BUCKET                 =  ' jc21-npm-site' 
26+ 		DOCS_CDN                    =  ' EN1G6DEWZUTDT' 
1927	}
2028	stages {
2129		stage(' Environment' 
@@ -26,7 +34,7 @@ pipeline {
2634					}
2735					steps {
2836						script {
29- 							env . BUILDX_PUSH_TAGS  =  " -t docker.io/jc21/${ IMAGE} ${ BUILD_VERSION} ${ IMAGE} ${ MAJOR_VERSION} ${ IMAGE} " 
37+ 							buildxPushTags  =  " -t docker.io/jc21/${ IMAGE} ${ BUILD_VERSION} ${ IMAGE} ${ MAJOR_VERSION} ${ IMAGE} " 
3038						}
3139					}
3240				}
@@ -39,7 +47,7 @@ pipeline {
3947					steps {
4048						script {
4149							//  Defaults to the Branch name, which is applies to all branches AND pr's
42- 							env . BUILDX_PUSH_TAGS  =  " -t docker.io/jc21/${ IMAGE} ${ BRANCH_LOWER} " 
50+ 							buildxPushTags  =  " -t docker.io/jc21/${ IMAGE} ${ BRANCH_LOWER} " 
4351						}
4452					}
4553				}
@@ -54,35 +62,28 @@ pipeline {
5462				}
5563			}
5664		}
57- 		stage(' Frontend ' 
65+ 		stage(' Build and Test ' 
5866			steps {
59- 				sh ' ./scripts/frontend-build' 
67+ 				script {
68+ 					//  Frontend and Backend
69+ 					def  shStatusCode =  sh(label : ' Checking and Building' returnStatus : true , script : ''' 
70+ 						set -e 
71+ 						./scripts/ci/frontend-build > ${WORKSPACE}/tmp-sh-build 2>&1 
72+ 						./scripts/ci/test-and-build > ${WORKSPACE}/tmp-sh-build 2>&1 
73+ 					'''  )
74+ 					shOutput =  readFile " ${ env.WORKSPACE} " 
75+ 					if  (shStatusCode !=  0 ) {
76+ 						error " ${ shOutput} " 
77+ 					}
78+ 				}
6079			}
61- 		}
62- 		stage(' Backend' 
63- 			steps {
64- 				echo ' Checking Syntax ...' 
65- 				sh ' docker pull nginxproxymanager/nginx-full:certbot-node' 
66- 				//  See: https://github.com/yarnpkg/yarn/issues/3254
67- 				sh ''' docker run --rm \\ 
68- 					-v "$(pwd)/backend:/app" \\  
69- 					-v "$(pwd)/global:/app/global" \\  
70- 					-w /app \\  
71- 					nginxproxymanager/nginx-full:certbot-node \\  
72- 					sh -c "yarn install && yarn eslint . && rm -rf node_modules" 
73- 				'''  
74- 
75- 				echo ' Docker Build ...' 
76- 				sh ''' docker build --pull --no-cache --squash --compress \\ 
77- 					-t "${IMAGE}:ci-${BUILD_NUMBER}" \\  
78- 					-f docker/Dockerfile \\  
79- 					--build-arg TARGETPLATFORM=linux/amd64 \\  
80- 					--build-arg BUILDPLATFORM=linux/amd64 \\  
81- 					--build-arg BUILD_VERSION="${BUILD_VERSION}" \\  
82- 					--build-arg BUILD_COMMIT="${BUILD_COMMIT}" \\  
83- 					--build-arg BUILD_DATE="$(date '+%Y-%m-%d %T %Z')" \\  
84- 					. 
85- 				'''  
80+ 			post {
81+ 				always {
82+ 					sh ' rm -f ${WORKSPACE}/tmp-sh-build' 
83+ 				}
84+ 				failure {
85+ 					npmGithubPrComment(" CI Error:\n\n ```\n ${ shOutput} \n ```" true )
86+ 				}
8687			}
8788		}
8889		stage(' Integration Tests Sqlite' 
@@ -164,10 +165,8 @@ pipeline {
164165			}
165166			steps {
166167				withCredentials([usernamePassword(credentialsId : ' jc21-dockerhub' passwordVariable : ' dpass' usernameVariable : ' duser' 
167- 					//  Docker Login
168- 					sh " docker login -u '${ duser} ${ dpass} " 
169- 					//  Buildx with push from cache
170- 					sh " ./scripts/buildx --push ${ BUILDX_PUSH_TAGS} " 
168+ 					sh ' docker login -u "${duser}" -p "${dpass}"' 
169+ 					sh " ./scripts/buildx --push ${ buildxPushTags} " 
171170				}
172171			}
173172		}
@@ -181,26 +180,7 @@ pipeline {
181180				}
182181			}
183182			steps {
184- 				withCredentials([[$class : ' AmazonWebServicesCredentialsBinding' accessKeyVariable : ' AWS_ACCESS_KEY_ID' credentialsId : ' npm-s3-docs' secretKeyVariable : ' AWS_SECRET_ACCESS_KEY' 
185- 					sh """ docker run --rm \\ 
186- 						--name \$ {COMPOSE_PROJECT_NAME}-docs-upload \\  
187- 						-e S3_BUCKET=jc21-npm-site \\  
188- 						-e AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID   \\  
189- 						-e AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY   \\  
190- 						-v \$ (pwd):/app \\  
191- 						-w /app \\  
192- 						jc21/ci-tools \\  
193- 						scripts/docs-upload /app/docs/.vuepress/dist/ 
194- 					"""  
195- 
196- 					sh """ docker run --rm \\ 
197- 						--name \$ {COMPOSE_PROJECT_NAME}-docs-invalidate \\  
198- 						-e AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID   \\  
199- 						-e AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY   \\  
200- 						jc21/ci-tools \\  
201- 						aws cloudfront create-invalidation --distribution-id EN1G6DEWZUTDT --paths '/*' 
202- 					"""  
203- 				}
183+ 				npmDocsRelease(" $DOCS_BUCKET  " " $DOCS_CDN  " 
204184			}
205185		}
206186		stage(' PR Comment' 
@@ -214,7 +194,7 @@ pipeline {
214194			}
215195			steps {
216196				script {
217- 					def  comment  =  pullRequest . comment( " This is an automated message from CI: \n\n Docker  Image for build ${ BUILD_NUMBER} ${ IMAGE} ${ IMAGE} ${ BRANCH_LOWER} \n\n **Note:** ensure you backup your NPM instance before testing this PR image! Especially if this PR contains database changes." 
197+ 					npmGithubPrComment( " Docker  Image for build ${ BUILD_NUMBER} ${ IMAGE} ${ IMAGE} ${ BRANCH_LOWER} \n\n **Note:** ensure you backup your NPM instance before testing this PR image! Especially if this PR contains database changes." ,  true )
218198				}
219199			}
220200		}
0 commit comments