From 56ac47dc16aaadd8cc44d3ef56f2d1da534243d4 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Tue, 30 Jan 2024 18:52:31 +0100 Subject: [PATCH 01/22] build: refs #5483 send rocket message, skip steps when run source isn't git --- Jenkinsfile | 57 +++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 44 insertions(+), 13 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index c65b01d47..51ae7de43 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -6,7 +6,7 @@ pipeline { } environment { PROJECT_NAME = 'salix' - STACK_NAME = "${env.PROJECT_NAME}-${env.BRANCH_NAME}" + STACK_NAME = "${env.PROJECT_NAME}-${env.BRANCH_NAME}" } stages { stage('Checkout') { @@ -22,6 +22,9 @@ pipeline { env.BACK_REPLICAS = 2 break } + + if (env.JOB_NAME.startsWith('gitea/') + env.RUN_SOURCE = 'git' } configFileProvider([ @@ -46,10 +49,13 @@ pipeline { } } stage('Test') { - when { not { anyOf { - branch 'test' - branch 'master' - }}} + when { + environment name: 'RUN_SOURCE', value: 'git' + not { anyOf { + branch 'test' + branch 'master' + }} + } environment { NODE_ENV = "" TZ = 'Europe/Madrid' @@ -72,10 +78,13 @@ pipeline { } } stage('Build') { - when { anyOf { - branch 'test' - branch 'master' - }} + when { + environment name: 'RUN_SOURCE', value: 'git' + anyOf { + branch 'test' + branch 'master' + } + } environment { CREDENTIALS = credentials('docker-registry') } @@ -88,10 +97,13 @@ pipeline { } } stage('Deploy') { - when { anyOf { - branch 'test' - branch 'master' - }} + when { + environment name: 'RUN_SOURCE', value: 'git' + anyOf { + branch 'test' + branch 'master' + } + } environment { DOCKER_HOST = "${env.SWARM_HOST}" } @@ -120,6 +132,25 @@ pipeline { } } post { + success { + script { + if (env.RUN_SOURCE == 'git' + && ['master', 'test'].contains(env.BRANCH_NAME)) { + String message = env.GIT_COMMIT_MSG + int index = message.indexOf('\n') + if (index != -1) + message = message.substring(0, index) + + rocketSend( + channel: 'vn-database', + message: "*DB version uploaded:* ${message}" + +"\n$COMMITTER_EMAIL ($BRANCH_NAME)" + +"\n$GIT_URL/commit/$GIT_COMMIT", + rawMessage: true + ) + } + } + } always { script { if (!['master', 'test'].contains(env.BRANCH_NAME)) { From 79f509ca46bdf65dc90598e45d2f6d785c1f1575 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Tue, 30 Jan 2024 18:54:41 +0100 Subject: [PATCH 02/22] fix: refs #5483 Jenkinsfile code fix --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 51ae7de43..88e677121 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -23,7 +23,7 @@ pipeline { break } - if (env.JOB_NAME.startsWith('gitea/') + if (env.JOB_NAME.startsWith('gitea/')) env.RUN_SOURCE = 'git' } From 12af7579298090f17b9d8ae46a987f1d7319fcf3 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Tue, 30 Jan 2024 19:01:14 +0100 Subject: [PATCH 03/22] refs #5483 Jenkinsfile fix --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 88e677121..181e0b02e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -119,7 +119,7 @@ pipeline { }} steps { configFileProvider([ - configFile(fileId: "config.${NODE_ENV}.ini", + configFile(fileId: "config.${env.NODE_ENV}.ini", variable: 'MYSQL_CONFIG') ]) { sh 'mkdir -p db/remotes' From 624f61465ae0500ec5f05c538872e527bc1c695e Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Tue, 30 Jan 2024 19:05:55 +0100 Subject: [PATCH 04/22] fix: refs #5483 Jenkinsfile fixes --- Jenkinsfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index 181e0b02e..5552ccdc6 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -21,6 +21,9 @@ pipeline { env.NODE_ENV = 'test' env.BACK_REPLICAS = 2 break + case 'dev': + env.NODE_ENV = 'dev' + break } if (env.JOB_NAME.startsWith('gitea/')) From 17c9054155386f75d829422c9249562b95bff800 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Tue, 30 Jan 2024 19:30:26 +0100 Subject: [PATCH 05/22] fix: refs #5483 Jenkinsfile fixes --- Jenkinsfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 5552ccdc6..713a63c52 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -156,7 +156,8 @@ pipeline { } always { script { - if (!['master', 'test'].contains(env.BRANCH_NAME)) { + if (env.RUN_SOURCE == 'git' + && !['master', 'test'].contains(env.BRANCH_NAME)) { try { junit 'junitresults.xml' junit 'junit.xml' From 095d6b4140a22c5ac4447182e10fc5b374107a50 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Tue, 30 Jan 2024 19:35:23 +0100 Subject: [PATCH 06/22] fix: refs #5483 Unused code removed --- Jenkinsfile | 8 -------- 1 file changed, 8 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 713a63c52..37f1abc9e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -29,14 +29,6 @@ pipeline { if (env.JOB_NAME.startsWith('gitea/')) env.RUN_SOURCE = 'git' } - - configFileProvider([ - configFile(fileId: "salix.groovy", - variable: 'GROOVY_FILE') - ]) { - load env.GROOVY_FILE - } - setEnv() } } From 84961dda4952041fd791875820bf0088eb5fe301 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Tue, 30 Jan 2024 19:41:09 +0100 Subject: [PATCH 07/22] build: refs #5483 test workers increased to 6, test rocket notification --- Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 37f1abc9e..20b64de0d 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -59,7 +59,7 @@ pipeline { stage('Frontend') { steps { nodejs('node-v20') { - sh 'jest --ci --reporters=default --reporters=jest-junit --maxWorkers=4' + sh 'jest --ci --reporters=default --reporters=jest-junit --maxWorkers=6' } } } @@ -130,7 +130,7 @@ pipeline { success { script { if (env.RUN_SOURCE == 'git' - && ['master', 'test'].contains(env.BRANCH_NAME)) { + && ['master', 'test', 'dev'].contains(env.BRANCH_NAME)) { String message = env.GIT_COMMIT_MSG int index = message.indexOf('\n') if (index != -1) From 3e0ebc0f26388544ed6fd821f5c1c83cbe096ca7 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Tue, 30 Jan 2024 19:45:37 +0100 Subject: [PATCH 08/22] fix: refs #5483 Jenkinsfile rocketchat fixes --- Jenkinsfile | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index 20b64de0d..11fcbb752 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -26,6 +26,11 @@ pipeline { break } + env.GIT_COMMIT_MSG = sh( + script: 'git log -1 --pretty=%B ${GIT_COMMIT}', + returnStdout: true + ).trim() + if (env.JOB_NAME.startsWith('gitea/')) env.RUN_SOURCE = 'git' } From 1a64126655dcff9cdd1185b089fe59cac7f3356f Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Tue, 30 Jan 2024 19:51:30 +0100 Subject: [PATCH 09/22] build: refs #5483 Jenkinsfile parallel deploy --- Jenkinsfile | 64 ++++++++++++++++++++++++++++------------------------- 1 file changed, 34 insertions(+), 30 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 11fcbb752..8767a1150 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -97,36 +97,40 @@ pipeline { } } stage('Deploy') { - when { - environment name: 'RUN_SOURCE', value: 'git' - anyOf { - branch 'test' - branch 'master' + parallel { + stage('Docker') { + when { + environment name: 'RUN_SOURCE', value: 'git' + anyOf { + branch 'test' + branch 'master' + } + } + environment { + DOCKER_HOST = "${env.SWARM_HOST}" + } + steps { + sh "docker stack deploy --with-registry-auth --compose-file docker-compose.yml ${env.STACK_NAME}" + } } - } - environment { - DOCKER_HOST = "${env.SWARM_HOST}" - } - steps { - sh "docker stack deploy --with-registry-auth --compose-file docker-compose.yml ${env.STACK_NAME}" - } - } - stage('Database') { - when { anyOf { - branch 'dev' - branch 'test' - branch 'master' - }} - steps { - configFileProvider([ - configFile(fileId: "config.${env.NODE_ENV}.ini", - variable: 'MYSQL_CONFIG') - ]) { - sh 'mkdir -p db/remotes' - sh 'cp "$MYSQL_CONFIG" db/remotes/$NODE_ENV.ini' - } - nodejs('node-v20') { - sh 'npx myt push $NODE_ENV --force --commit' + stage('Database') { + when { anyOf { + branch 'dev' + branch 'test' + branch 'master' + }} + steps { + configFileProvider([ + configFile(fileId: "config.${env.NODE_ENV}.ini", + variable: 'MYSQL_CONFIG') + ]) { + sh 'mkdir -p db/remotes' + sh 'cp "$MYSQL_CONFIG" db/remotes/$NODE_ENV.ini' + } + nodejs('node-v20') { + sh 'npx myt push $NODE_ENV --force --commit' + } + } } } } @@ -135,7 +139,7 @@ pipeline { success { script { if (env.RUN_SOURCE == 'git' - && ['master', 'test', 'dev'].contains(env.BRANCH_NAME)) { + && ['master', 'test'].contains(env.BRANCH_NAME)) { String message = env.GIT_COMMIT_MSG int index = message.indexOf('\n') if (index != -1) From 7d2b5fbedaad169197ae132f4151ce736eaf50b7 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Tue, 30 Jan 2024 20:04:32 +0100 Subject: [PATCH 10/22] build: refs #5483 Parallel install, code reorder --- Jenkinsfile | 69 +++++++++++++++++++++++++++++++++-------------------- 1 file changed, 43 insertions(+), 26 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 8767a1150..3ffa98394 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -41,10 +41,27 @@ pipeline { environment { NODE_ENV = "" } - steps { - nodejs('node-v20') { - sh 'npm install --no-audit --prefer-offline' - sh 'gulp install --ci' + parallel { + stage('Backend') { + steps { + nodejs('node-v20') { + sh 'npm install --no-audit --prefer-offline' + } + } + } + stage('Frontend') { + steps { + nodejs('node-v20') { + sh 'npm install --no-audit --prefer-offline --prefix=front' + } + } + } + stage('Print') { + steps { + nodejs('node-v20') { + sh 'npm install --no-audit --prefer-offline --prefix=print' + } + } } } } @@ -61,13 +78,6 @@ pipeline { TZ = 'Europe/Madrid' } parallel { - stage('Frontend') { - steps { - nodejs('node-v20') { - sh 'jest --ci --reporters=default --reporters=jest-junit --maxWorkers=6' - } - } - } stage('Backend') { steps { nodejs('node-v20') { @@ -75,6 +85,13 @@ pipeline { } } } + stage('Frontend') { + steps { + nodejs('node-v20') { + sh 'jest --ci --reporters=default --reporters=jest-junit --maxWorkers=6' + } + } + } } } stage('Build') { @@ -98,21 +115,6 @@ pipeline { } stage('Deploy') { parallel { - stage('Docker') { - when { - environment name: 'RUN_SOURCE', value: 'git' - anyOf { - branch 'test' - branch 'master' - } - } - environment { - DOCKER_HOST = "${env.SWARM_HOST}" - } - steps { - sh "docker stack deploy --with-registry-auth --compose-file docker-compose.yml ${env.STACK_NAME}" - } - } stage('Database') { when { anyOf { branch 'dev' @@ -132,6 +134,21 @@ pipeline { } } } + stage('Docker') { + when { + environment name: 'RUN_SOURCE', value: 'git' + anyOf { + branch 'test' + branch 'master' + } + } + environment { + DOCKER_HOST = "${env.SWARM_HOST}" + } + steps { + sh "docker stack deploy --with-registry-auth --compose-file docker-compose.yml ${env.STACK_NAME}" + } + } } } } From 027f7d2c1dc8e44711ee802a7e5ed1b1e3780613 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Tue, 30 Jan 2024 20:41:24 +0100 Subject: [PATCH 11/22] build: refs #5483 dev deploy, tag image with version --- Jenkinsfile | 46 ++++++++++++++++++++++++++++++---------------- docker-compose.yml | 8 ++++++-- package.json | 2 +- 3 files changed, 37 insertions(+), 19 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 3ffa98394..a73047b31 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -8,24 +8,41 @@ pipeline { PROJECT_NAME = 'salix' STACK_NAME = "${env.PROJECT_NAME}-${env.BRANCH_NAME}" } + parameters { + booleanParam( + name: 'PROTECTED_BRANCH', + defaultValue: false, + description: 'Whether branch is a protected branch' + ) + } stages { stage('Checkout') { steps { script { + def packageJson = readJSON file: 'package.json' + env.VERSION = packageJson.version + switch (env.BRANCH_NAME) { - case 'master': - env.NODE_ENV = 'production' - env.BACK_REPLICAS = 4 + case 'dev': + env.NODE_ENV = 'dev' + env.BACK_REPLICAS = 1 break case 'test': env.NODE_ENV = 'test' env.BACK_REPLICAS = 2 break - case 'dev': - env.NODE_ENV = 'dev' + case 'master': + env.NODE_ENV = 'production' + env.BACK_REPLICAS = 4 break } + params.PROTECTED_BRANCH = [ + 'dev', + 'test', + 'master' + ].contains(env.BRANCH_NAME) + env.GIT_COMMIT_MSG = sh( script: 'git log -1 --pretty=%B ${GIT_COMMIT}', returnStdout: true @@ -69,6 +86,7 @@ pipeline { when { environment name: 'RUN_SOURCE', value: 'git' not { anyOf { + branch 'dev' branch 'test' branch 'master' }} @@ -98,6 +116,7 @@ pipeline { when { environment name: 'RUN_SOURCE', value: 'git' anyOf { + branch 'dev' branch 'test' branch 'master' } @@ -114,13 +133,13 @@ pipeline { } } stage('Deploy') { + when { anyOf { + branch 'dev' + branch 'test' + branch 'master' + }} parallel { stage('Database') { - when { anyOf { - branch 'dev' - branch 'test' - branch 'master' - }} steps { configFileProvider([ configFile(fileId: "config.${env.NODE_ENV}.ini", @@ -137,10 +156,6 @@ pipeline { stage('Docker') { when { environment name: 'RUN_SOURCE', value: 'git' - anyOf { - branch 'test' - branch 'master' - } } environment { DOCKER_HOST = "${env.SWARM_HOST}" @@ -155,8 +170,7 @@ pipeline { post { success { script { - if (env.RUN_SOURCE == 'git' - && ['master', 'test'].contains(env.BRANCH_NAME)) { + if (env.RUN_SOURCE == 'git' && env.BRANCH_NAME == 'master') { String message = env.GIT_COMMIT_MSG int index = message.indexOf('\n') if (index != -1) diff --git a/docker-compose.yml b/docker-compose.yml index 0d2db1a63..32bcb1777 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,9 @@ version: '3.7' services: front: - image: registry.verdnatura.es/salix-front:${BRANCH_NAME:?} + image: registry.verdnatura.es/salix-front:${VERSION:?} + tags: + - ${BRANCH_NAME:?} build: context: . dockerfile: front/Dockerfile @@ -16,7 +18,9 @@ services: limits: memory: 1G back: - image: registry.verdnatura.es/salix-back:${BRANCH_NAME:?} + image: registry.verdnatura.es/salix-back:${VERSION:?} + tags: + - ${BRANCH_NAME:?} build: . ports: - 3000 diff --git a/package.json b/package.json index 3f3a3ad8e..041bd39df 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "salix-back", - "version": "24.06.01", + "version": "24.6.0", "author": "Verdnatura Levante SL", "description": "Salix backend", "license": "GPL-3.0", From 29634e16e5bed2651c9a4e741ef0a06cca79fa53 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Tue, 30 Jan 2024 20:44:33 +0100 Subject: [PATCH 12/22] fix: refs #5483 Jenkinsfile fix --- Jenkinsfile | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index a73047b31..f4d429765 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -8,13 +8,6 @@ pipeline { PROJECT_NAME = 'salix' STACK_NAME = "${env.PROJECT_NAME}-${env.BRANCH_NAME}" } - parameters { - booleanParam( - name: 'PROTECTED_BRANCH', - defaultValue: false, - description: 'Whether branch is a protected branch' - ) - } stages { stage('Checkout') { steps { @@ -37,7 +30,7 @@ pipeline { break } - params.PROTECTED_BRANCH = [ + env.PROTECTED_BRANCH = [ 'dev', 'test', 'master' From 76545cd1accfc8caca5ccd40bcf599f51d7c9c64 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Tue, 30 Jan 2024 20:58:15 +0100 Subject: [PATCH 13/22] fix: refs #5483 Jenkinsfile & compose fixes --- Jenkinsfile | 56 +++++++++++++++------------------------------- docker-compose.yml | 4 ++-- 2 files changed, 20 insertions(+), 40 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index f4d429765..1f99f2115 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -12,9 +12,6 @@ pipeline { stage('Checkout') { steps { script { - def packageJson = readJSON file: 'package.json' - env.VERSION = packageJson.version - switch (env.BRANCH_NAME) { case 'dev': env.NODE_ENV = 'dev' @@ -30,6 +27,11 @@ pipeline { break } + def packageJson = readJSON file: 'package.json' + env.VERSION = packageJson.version + + env.FROM_GIT = env.JOB_NAME.startsWith('gitea/') + env.PROTECTED_BRANCH = [ 'dev', 'test', @@ -40,9 +42,6 @@ pipeline { script: 'git log -1 --pretty=%B ${GIT_COMMIT}', returnStdout: true ).trim() - - if (env.JOB_NAME.startsWith('gitea/')) - env.RUN_SOURCE = 'git' } setEnv() } @@ -77,12 +76,8 @@ pipeline { } stage('Test') { when { - environment name: 'RUN_SOURCE', value: 'git' - not { anyOf { - branch 'dev' - branch 'test' - branch 'master' - }} + expression { return env.FROM_GIT } + expression { return !env.PROTECTED_BRANCH } } environment { NODE_ENV = "" @@ -107,12 +102,8 @@ pipeline { } stage('Build') { when { - environment name: 'RUN_SOURCE', value: 'git' - anyOf { - branch 'dev' - branch 'test' - branch 'master' - } + expression { return env.FROM_GIT } + expression { return env.PROTECTED_BRANCH } } environment { CREDENTIALS = credentials('docker-registry') @@ -126,11 +117,9 @@ pipeline { } } stage('Deploy') { - when { anyOf { - branch 'dev' - branch 'test' - branch 'master' - }} + when { + expression { return env.PROTECTED_BRANCH } + } parallel { stage('Database') { steps { @@ -148,7 +137,7 @@ pipeline { } stage('Docker') { when { - environment name: 'RUN_SOURCE', value: 'git' + expression { return env.FROM_GIT } } environment { DOCKER_HOST = "${env.SWARM_HOST}" @@ -163,7 +152,7 @@ pipeline { post { success { script { - if (env.RUN_SOURCE == 'git' && env.BRANCH_NAME == 'master') { + if (env.FROM_GIT && env.BRANCH_NAME == 'master') { String message = env.GIT_COMMIT_MSG int index = message.indexOf('\n') if (index != -1) @@ -179,10 +168,12 @@ pipeline { } } } + unsuccessful { + sendEmail() + } always { script { - if (env.RUN_SOURCE == 'git' - && !['master', 'test'].contains(env.BRANCH_NAME)) { + if (env.FROM_GIT && !env.PROTECTED_BRANCH) { try { junit 'junitresults.xml' junit 'junit.xml' @@ -190,17 +181,6 @@ pipeline { echo e.toString() } } - - if (!env.COMMITTER_EMAIL || currentBuild.currentResult == 'SUCCESS') return; - try { - mail( - to: env.COMMITTER_EMAIL, - subject: "Pipeline: ${env.JOB_NAME} (${env.BUILD_NUMBER}): ${currentBuild.currentResult}", - body: "Check status at ${env.BUILD_URL}" - ) - } catch (e) { - echo e.toString() - } } } } diff --git a/docker-compose.yml b/docker-compose.yml index 32bcb1777..6bcf30e2d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,7 +3,7 @@ services: front: image: registry.verdnatura.es/salix-front:${VERSION:?} tags: - - ${BRANCH_NAME:?} + - "${BRANCH_NAME:?}" build: context: . dockerfile: front/Dockerfile @@ -20,7 +20,7 @@ services: back: image: registry.verdnatura.es/salix-back:${VERSION:?} tags: - - ${BRANCH_NAME:?} + - "${BRANCH_NAME:?}" build: . ports: - 3000 From 4251f29a1773394b3ecbb348deb9b7df68ce4df6 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Tue, 30 Jan 2024 21:05:59 +0100 Subject: [PATCH 14/22] fix: refs #5483 compose fixes --- docker-compose.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 6bcf30e2d..222e753d7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,8 +2,6 @@ version: '3.7' services: front: image: registry.verdnatura.es/salix-front:${VERSION:?} - tags: - - "${BRANCH_NAME:?}" build: context: . dockerfile: front/Dockerfile @@ -19,8 +17,6 @@ services: memory: 1G back: image: registry.verdnatura.es/salix-back:${VERSION:?} - tags: - - "${BRANCH_NAME:?}" build: . ports: - 3000 From 4d065a2f797ee249412ffbc80f2ec7f2e8f4ccd4 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Tue, 30 Jan 2024 21:37:20 +0100 Subject: [PATCH 15/22] fix: refs #5483 Jenkinsfile fixes, global nodejs tool --- Jenkinsfile | 70 ++++++++++++++++++++++------------------------------- 1 file changed, 29 insertions(+), 41 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 1f99f2115..4688e5283 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -8,6 +8,9 @@ pipeline { PROJECT_NAME = 'salix' STACK_NAME = "${env.PROJECT_NAME}-${env.BRANCH_NAME}" } + tools { + nodejs 'node-v20' + } stages { stage('Checkout') { steps { @@ -30,8 +33,6 @@ pipeline { def packageJson = readJSON file: 'package.json' env.VERSION = packageJson.version - env.FROM_GIT = env.JOB_NAME.startsWith('gitea/') - env.PROTECTED_BRANCH = [ 'dev', 'test', @@ -42,6 +43,9 @@ pipeline { script: 'git log -1 --pretty=%B ${GIT_COMMIT}', returnStdout: true ).trim() + + env.FROM_GIT = env.JOB_NAME.startsWith('gitea/') + env.RUN_TESTS = !env.PROTECTED_BRANCH && env.FROM_GIT } setEnv() } @@ -53,31 +57,24 @@ pipeline { parallel { stage('Backend') { steps { - nodejs('node-v20') { - sh 'npm install --no-audit --prefer-offline' - } + sh 'npm install --no-audit --prefer-offline' } } stage('Frontend') { steps { - nodejs('node-v20') { - sh 'npm install --no-audit --prefer-offline --prefix=front' - } + sh 'npm install --no-audit --prefer-offline --prefix=front' } } stage('Print') { steps { - nodejs('node-v20') { - sh 'npm install --no-audit --prefer-offline --prefix=print' - } + sh 'npm install --no-audit --prefer-offline --prefix=print' } } } } stage('Test') { when { - expression { return env.FROM_GIT } - expression { return !env.PROTECTED_BRANCH } + expression { return env.RUN_TESTS } } environment { NODE_ENV = "" @@ -86,33 +83,25 @@ pipeline { parallel { stage('Backend') { steps { - nodejs('node-v20') { - sh 'npm run test:back:ci' - } + sh 'npm run test:back:ci' } } stage('Frontend') { steps { - nodejs('node-v20') { - sh 'jest --ci --reporters=default --reporters=jest-junit --maxWorkers=6' - } + sh 'jest --ci --reporters=default --reporters=jest-junit --maxWorkers=6' } } } } stage('Build') { when { - expression { return env.FROM_GIT } - expression { return env.PROTECTED_BRANCH } + expression { return env.PROTECTED_BRANCH && env.FROM_GIT } } environment { CREDENTIALS = credentials('docker-registry') } steps { - nodejs('node-v20') { - sh 'gulp build' - } - + sh 'gulp build' dockerBuild() } } @@ -130,9 +119,8 @@ pipeline { sh 'mkdir -p db/remotes' sh 'cp "$MYSQL_CONFIG" db/remotes/$NODE_ENV.ini' } - nodejs('node-v20') { - sh 'npx myt push $NODE_ENV --force --commit' - } + + sh 'npx myt push $NODE_ENV --force --commit' } } stage('Docker') { @@ -150,9 +138,21 @@ pipeline { } } post { + always { + script { + if (env.RUN_TESTS) { + try { + junit 'junitresults.xml' + junit 'junit.xml' + } catch (e) { + echo e.toString() + } + } + } + } success { script { - if (env.FROM_GIT && env.BRANCH_NAME == 'master') { + if (env.BRANCH_NAME == 'master' && env.FROM_GIT) { String message = env.GIT_COMMIT_MSG int index = message.indexOf('\n') if (index != -1) @@ -171,17 +171,5 @@ pipeline { unsuccessful { sendEmail() } - always { - script { - if (env.FROM_GIT && !env.PROTECTED_BRANCH) { - try { - junit 'junitresults.xml' - junit 'junit.xml' - } catch (e) { - echo e.toString() - } - } - } - } } } From 420398260ff02920b4dffff6474a94f4668f197a Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Tue, 30 Jan 2024 21:49:58 +0100 Subject: [PATCH 16/22] fix: refs #5483 Jenkinsfile codefix --- Jenkinsfile | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 4688e5283..d0c4614ca 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,4 +1,9 @@ #!/usr/bin/env groovy + +def PROTECTED_BRANCH +def FROM_GIT +def RUN_TESTS + pipeline { agent any options { @@ -33,19 +38,19 @@ pipeline { def packageJson = readJSON file: 'package.json' env.VERSION = packageJson.version - env.PROTECTED_BRANCH = [ - 'dev', - 'test', - 'master' - ].contains(env.BRANCH_NAME) - env.GIT_COMMIT_MSG = sh( script: 'git log -1 --pretty=%B ${GIT_COMMIT}', returnStdout: true ).trim() - env.FROM_GIT = env.JOB_NAME.startsWith('gitea/') - env.RUN_TESTS = !env.PROTECTED_BRANCH && env.FROM_GIT + PROTECTED_BRANCH = [ + 'dev', + 'test', + 'master' + ].contains(env.BRANCH_NAME) + + FROM_GIT = JOB_NAME.startsWith('gitea/') + RUN_TESTS = !PROTECTED_BRANCH && FROM_GIT } setEnv() } @@ -74,7 +79,7 @@ pipeline { } stage('Test') { when { - expression { return env.RUN_TESTS } + expression { return RUN_TESTS } } environment { NODE_ENV = "" @@ -95,7 +100,7 @@ pipeline { } stage('Build') { when { - expression { return env.PROTECTED_BRANCH && env.FROM_GIT } + expression { return PROTECTED_BRANCH && FROM_GIT } } environment { CREDENTIALS = credentials('docker-registry') @@ -107,7 +112,7 @@ pipeline { } stage('Deploy') { when { - expression { return env.PROTECTED_BRANCH } + expression { return PROTECTED_BRANCH } } parallel { stage('Database') { @@ -125,7 +130,7 @@ pipeline { } stage('Docker') { when { - expression { return env.FROM_GIT } + expression { return FROM_GIT } } environment { DOCKER_HOST = "${env.SWARM_HOST}" @@ -140,7 +145,7 @@ pipeline { post { always { script { - if (env.RUN_TESTS) { + if (RUN_TESTS) { try { junit 'junitresults.xml' junit 'junit.xml' @@ -152,7 +157,7 @@ pipeline { } success { script { - if (env.BRANCH_NAME == 'master' && env.FROM_GIT) { + if (env.BRANCH_NAME == 'master' && FROM_GIT) { String message = env.GIT_COMMIT_MSG int index = message.indexOf('\n') if (index != -1) From 7ab11543edb661c04a899c587e34835db341e694 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Tue, 30 Jan 2024 21:57:04 +0100 Subject: [PATCH 17/22] build: refs #5483 Jenkinsfile optimized for daily DB push --- Jenkinsfile | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index d0c4614ca..8f1ada293 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -66,11 +66,17 @@ pipeline { } } stage('Frontend') { + when { + expression { return FROM_GIT } + } steps { sh 'npm install --no-audit --prefer-offline --prefix=front' } } stage('Print') { + when { + expression { return FROM_GIT } + } steps { sh 'npm install --no-audit --prefer-offline --prefix=print' } From 53ac10d0becf2ccf76a4900dd35690a81d4c30c4 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Tue, 30 Jan 2024 22:33:55 +0100 Subject: [PATCH 18/22] build: refs #6706 hook test --- Jenkinsfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 8f1ada293..2b9e169b2 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -9,13 +9,13 @@ pipeline { options { disableConcurrentBuilds() } + tools { + nodejs 'node-v20' + } environment { PROJECT_NAME = 'salix' STACK_NAME = "${env.PROJECT_NAME}-${env.BRANCH_NAME}" } - tools { - nodejs 'node-v20' - } stages { stage('Checkout') { steps { From e4f62e4e065b8418e19b32f51ca3a525ec40f9a7 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Tue, 30 Jan 2024 22:53:33 +0100 Subject: [PATCH 19/22] build: refs #6706 hook test --- Jenkinsfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 2b9e169b2..8f1ada293 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -9,13 +9,13 @@ pipeline { options { disableConcurrentBuilds() } - tools { - nodejs 'node-v20' - } environment { PROJECT_NAME = 'salix' STACK_NAME = "${env.PROJECT_NAME}-${env.BRANCH_NAME}" } + tools { + nodejs 'node-v20' + } stages { stage('Checkout') { steps { From 67db31e39b923ce569d327842c4010f7b4ff0ed8 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Tue, 30 Jan 2024 23:06:12 +0100 Subject: [PATCH 20/22] build: refs #6706 hook test --- Jenkinsfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 8f1ada293..2b9e169b2 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -9,13 +9,13 @@ pipeline { options { disableConcurrentBuilds() } + tools { + nodejs 'node-v20' + } environment { PROJECT_NAME = 'salix' STACK_NAME = "${env.PROJECT_NAME}-${env.BRANCH_NAME}" } - tools { - nodejs 'node-v20' - } stages { stage('Checkout') { steps { From 827586ebd683bc7eef93483d7dcc0fab358e7739 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Tue, 30 Jan 2024 23:14:51 +0100 Subject: [PATCH 21/22] build: refs #6706 hook test --- Jenkinsfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 2b9e169b2..8f1ada293 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -9,13 +9,13 @@ pipeline { options { disableConcurrentBuilds() } - tools { - nodejs 'node-v20' - } environment { PROJECT_NAME = 'salix' STACK_NAME = "${env.PROJECT_NAME}-${env.BRANCH_NAME}" } + tools { + nodejs 'node-v20' + } stages { stage('Checkout') { steps { From 6d01164fb32d72146b95a0b1fb9e7a29d9f8e018 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Tue, 30 Jan 2024 23:25:14 +0100 Subject: [PATCH 22/22] build: refs #6706 hook test --- Jenkinsfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 8f1ada293..2b9e169b2 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -9,13 +9,13 @@ pipeline { options { disableConcurrentBuilds() } + tools { + nodejs 'node-v20' + } environment { PROJECT_NAME = 'salix' STACK_NAME = "${env.PROJECT_NAME}-${env.BRANCH_NAME}" } - tools { - nodejs 'node-v20' - } stages { stage('Checkout') { steps {