From 76545cd1accfc8caca5ccd40bcf599f51d7c9c64 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Tue, 30 Jan 2024 20:58:15 +0100 Subject: [PATCH] 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