0
0
Fork 0
salix-front-mindshore-fork2/Jenkinsfile

109 lines
2.6 KiB
Groovy

#!/usr/bin/env groovy
def PROTECTED_BRANCH
pre: {
switch (env.BRANCH_NAME) {
case 'test':
env.NODE_ENV = 'test'
env.BACK_REPLICAS = 2
break
case 'master':
env.NODE_ENV = 'production'
env.BACK_REPLICAS = 4
break
default:
env.NODE_ENV = 'dev'
env.BACK_REPLICAS = 1
}
PROTECTED_BRANCH = [
'dev',
'test',
'master'
].contains(env.BRANCH_NAME)
// Uncomment to enable debugging
// https://loopback.io/doc/en/lb3/Setting-debug-strings.html#debug-strings-reference
//env.DEBUG = 'strong-remoting:shared-method'
}
pipeline {
agent any
options {
disableConcurrentBuilds()
}
environment {
PROJECT_NAME = 'lilium'
STACK_NAME = "${env.PROJECT_NAME}-${env.BRANCH_NAME}"
}
stages {
stage('Install') {
environment {
NODE_ENV = ""
}
steps {
nodejs('node-v18') {
sh 'bun install --no-audit --prefer-offline'
}
}
}
stage('Test') {
when {
expression { !PROTECTED_BRANCH }
}
environment {
NODE_ENV = ""
}
parallel {
stage('Frontend') {
steps {
nodejs('node-v18') {
sh 'bun run test:unit:ci'
}
}
}
}
}
stage('Build') {
when {
expression { PROTECTED_BRANCH }
}
environment {
CREDENTIALS = credentials('docker-registry')
}
steps {
nodejs('node-v18') {
sh 'quasar build'
}
dockerBuild()
}
}
stage('Deploy') {
when {
expression { PROTECTED_BRANCH }
}
environment {
DOCKER_HOST = "${env.SWARM_HOST}"
}
steps {
sh "docker stack deploy --with-registry-auth --compose-file docker-compose.yml ${env.STACK_NAME}"
}
}
}
post {
always {
script {
if (!PROTECTED_BRANCH) {
try {
junit 'junitresults.xml'
junit 'junit.xml'
} catch (e) {
echo e.toString()
}
}
}
}
}
}