fix: refs #5483 Jenkinsfile & compose fixes
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Juan Ferrer 2024-01-30 20:58:15 +01:00
parent 29634e16e5
commit 76545cd1ac
2 changed files with 20 additions and 40 deletions

56
Jenkinsfile vendored
View File

@ -12,9 +12,6 @@ pipeline {
stage('Checkout') { stage('Checkout') {
steps { steps {
script { script {
def packageJson = readJSON file: 'package.json'
env.VERSION = packageJson.version
switch (env.BRANCH_NAME) { switch (env.BRANCH_NAME) {
case 'dev': case 'dev':
env.NODE_ENV = 'dev' env.NODE_ENV = 'dev'
@ -30,6 +27,11 @@ pipeline {
break break
} }
def packageJson = readJSON file: 'package.json'
env.VERSION = packageJson.version
env.FROM_GIT = env.JOB_NAME.startsWith('gitea/')
env.PROTECTED_BRANCH = [ env.PROTECTED_BRANCH = [
'dev', 'dev',
'test', 'test',
@ -40,9 +42,6 @@ pipeline {
script: 'git log -1 --pretty=%B ${GIT_COMMIT}', script: 'git log -1 --pretty=%B ${GIT_COMMIT}',
returnStdout: true returnStdout: true
).trim() ).trim()
if (env.JOB_NAME.startsWith('gitea/'))
env.RUN_SOURCE = 'git'
} }
setEnv() setEnv()
} }
@ -77,12 +76,8 @@ pipeline {
} }
stage('Test') { stage('Test') {
when { when {
environment name: 'RUN_SOURCE', value: 'git' expression { return env.FROM_GIT }
not { anyOf { expression { return !env.PROTECTED_BRANCH }
branch 'dev'
branch 'test'
branch 'master'
}}
} }
environment { environment {
NODE_ENV = "" NODE_ENV = ""
@ -107,12 +102,8 @@ pipeline {
} }
stage('Build') { stage('Build') {
when { when {
environment name: 'RUN_SOURCE', value: 'git' expression { return env.FROM_GIT }
anyOf { expression { return env.PROTECTED_BRANCH }
branch 'dev'
branch 'test'
branch 'master'
}
} }
environment { environment {
CREDENTIALS = credentials('docker-registry') CREDENTIALS = credentials('docker-registry')
@ -126,11 +117,9 @@ pipeline {
} }
} }
stage('Deploy') { stage('Deploy') {
when { anyOf { when {
branch 'dev' expression { return env.PROTECTED_BRANCH }
branch 'test' }
branch 'master'
}}
parallel { parallel {
stage('Database') { stage('Database') {
steps { steps {
@ -148,7 +137,7 @@ pipeline {
} }
stage('Docker') { stage('Docker') {
when { when {
environment name: 'RUN_SOURCE', value: 'git' expression { return env.FROM_GIT }
} }
environment { environment {
DOCKER_HOST = "${env.SWARM_HOST}" DOCKER_HOST = "${env.SWARM_HOST}"
@ -163,7 +152,7 @@ pipeline {
post { post {
success { success {
script { script {
if (env.RUN_SOURCE == 'git' && env.BRANCH_NAME == 'master') { if (env.FROM_GIT && env.BRANCH_NAME == 'master') {
String message = env.GIT_COMMIT_MSG String message = env.GIT_COMMIT_MSG
int index = message.indexOf('\n') int index = message.indexOf('\n')
if (index != -1) if (index != -1)
@ -179,10 +168,12 @@ pipeline {
} }
} }
} }
unsuccessful {
sendEmail()
}
always { always {
script { script {
if (env.RUN_SOURCE == 'git' if (env.FROM_GIT && !env.PROTECTED_BRANCH) {
&& !['master', 'test'].contains(env.BRANCH_NAME)) {
try { try {
junit 'junitresults.xml' junit 'junitresults.xml'
junit 'junit.xml' junit 'junit.xml'
@ -190,17 +181,6 @@ pipeline {
echo e.toString() 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()
}
} }
} }
} }

View File

@ -3,7 +3,7 @@ services:
front: front:
image: registry.verdnatura.es/salix-front:${VERSION:?} image: registry.verdnatura.es/salix-front:${VERSION:?}
tags: tags:
- ${BRANCH_NAME:?} - "${BRANCH_NAME:?}"
build: build:
context: . context: .
dockerfile: front/Dockerfile dockerfile: front/Dockerfile
@ -20,7 +20,7 @@ services:
back: back:
image: registry.verdnatura.es/salix-back:${VERSION:?} image: registry.verdnatura.es/salix-back:${VERSION:?}
tags: tags:
- ${BRANCH_NAME:?} - "${BRANCH_NAME:?}"
build: . build: .
ports: ports:
- 3000 - 3000