2022-03-29 10:53:02 +00:00
|
|
|
#!/usr/bin/env groovy
|
2024-02-05 08:42:21 +00:00
|
|
|
|
|
|
|
def PROTECTED_BRANCH
|
|
|
|
|
2024-02-20 13:40:35 +00:00
|
|
|
def BRANCH_ENV = [
|
|
|
|
test: 'test',
|
|
|
|
master: 'production'
|
|
|
|
]
|
|
|
|
|
|
|
|
node {
|
|
|
|
stage('Setup') {
|
2024-02-21 06:31:48 +00:00
|
|
|
env.FRONT_REPLICAS = 1
|
2024-02-20 13:40:35 +00:00
|
|
|
env.NODE_ENV = BRANCH_ENV[env.BRANCH_NAME] ?: 'dev'
|
|
|
|
|
|
|
|
PROTECTED_BRANCH = [
|
|
|
|
'dev',
|
|
|
|
'test',
|
|
|
|
'master'
|
|
|
|
].contains(env.BRANCH_NAME)
|
|
|
|
|
|
|
|
// https://www.jenkins.io/doc/book/pipeline/jenkinsfile/#using-environment-variables
|
|
|
|
echo "NODE_NAME: ${env.NODE_NAME}"
|
|
|
|
echo "WORKSPACE: ${env.WORKSPACE}"
|
2024-02-05 08:42:21 +00:00
|
|
|
|
2024-02-20 13:40:35 +00:00
|
|
|
configFileProvider([
|
|
|
|
configFile(fileId: 'salix-front.properties',
|
|
|
|
variable: 'PROPS_FILE')
|
|
|
|
]) {
|
|
|
|
def props = readProperties file: PROPS_FILE
|
|
|
|
props.each {key, value -> env."${key}" = value }
|
|
|
|
props.each {key, value -> echo "${key}: ${value}" }
|
|
|
|
}
|
2024-02-05 08:42:21 +00:00
|
|
|
|
2024-02-20 13:40:35 +00:00
|
|
|
if (PROTECTED_BRANCH) {
|
|
|
|
configFileProvider([
|
|
|
|
configFile(fileId: "salix-front.branch.${env.BRANCH_NAME}",
|
|
|
|
variable: 'BRANCH_PROPS_FILE')
|
|
|
|
]) {
|
|
|
|
def props = readProperties file: BRANCH_PROPS_FILE
|
|
|
|
props.each {key, value -> env."${key}" = value }
|
|
|
|
props.each {key, value -> echo "${key}: ${value}" }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-02-05 08:42:21 +00:00
|
|
|
}
|
|
|
|
|
2022-03-29 10:53:02 +00:00
|
|
|
pipeline {
|
|
|
|
agent any
|
|
|
|
options {
|
|
|
|
disableConcurrentBuilds()
|
|
|
|
}
|
2024-02-20 14:05:50 +00:00
|
|
|
tools {
|
|
|
|
nodejs 'node-v18'
|
|
|
|
}
|
2022-03-29 10:53:02 +00:00
|
|
|
environment {
|
2022-04-01 06:33:26 +00:00
|
|
|
PROJECT_NAME = 'lilium'
|
2022-03-29 10:53:02 +00:00
|
|
|
STACK_NAME = "${env.PROJECT_NAME}-${env.BRANCH_NAME}"
|
|
|
|
}
|
|
|
|
stages {
|
|
|
|
stage('Install') {
|
|
|
|
environment {
|
|
|
|
NODE_ENV = ""
|
|
|
|
}
|
|
|
|
steps {
|
2024-02-21 12:43:33 +00:00
|
|
|
sh 'npm install --prefer-offline'
|
2022-03-29 10:53:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
stage('Test') {
|
2024-02-05 08:42:21 +00:00
|
|
|
when {
|
|
|
|
expression { !PROTECTED_BRANCH }
|
|
|
|
}
|
2022-03-29 10:53:02 +00:00
|
|
|
environment {
|
|
|
|
NODE_ENV = ""
|
|
|
|
}
|
2024-02-21 12:14:04 +00:00
|
|
|
steps {
|
2024-02-21 12:43:33 +00:00
|
|
|
sh 'npm run test:unit:ci'
|
2024-02-21 12:14:04 +00:00
|
|
|
}
|
2024-02-27 08:39:19 +00:00
|
|
|
post {
|
2024-02-21 12:14:04 +00:00
|
|
|
always {
|
2024-02-27 08:39:19 +00:00
|
|
|
junit(
|
|
|
|
testResults: 'junitresults.xml',
|
|
|
|
allowEmptyResults: true
|
|
|
|
)
|
2022-03-29 10:53:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-03-30 13:29:20 +00:00
|
|
|
stage('Build') {
|
2024-02-05 08:42:21 +00:00
|
|
|
when {
|
|
|
|
expression { PROTECTED_BRANCH }
|
|
|
|
}
|
2022-03-30 13:29:20 +00:00
|
|
|
environment {
|
|
|
|
CREDENTIALS = credentials('docker-registry')
|
|
|
|
}
|
|
|
|
steps {
|
2024-02-20 14:05:50 +00:00
|
|
|
sh 'quasar build'
|
2024-02-21 11:08:49 +00:00
|
|
|
script {
|
|
|
|
def packageJson = readJSON file: 'package.json'
|
|
|
|
env.VERSION = packageJson.version
|
|
|
|
}
|
2024-02-21 11:04:55 +00:00
|
|
|
dockerBuild()
|
2022-03-30 13:29:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
stage('Deploy') {
|
2024-02-05 08:42:21 +00:00
|
|
|
when {
|
|
|
|
expression { PROTECTED_BRANCH }
|
|
|
|
}
|
2022-03-30 13:29:20 +00:00
|
|
|
environment {
|
|
|
|
DOCKER_HOST = "${env.SWARM_HOST}"
|
|
|
|
}
|
|
|
|
steps {
|
2024-02-20 14:05:50 +00:00
|
|
|
script {
|
|
|
|
def packageJson = readJSON file: 'package.json'
|
|
|
|
env.VERSION = packageJson.version
|
|
|
|
}
|
2022-03-30 13:29:20 +00:00
|
|
|
sh "docker stack deploy --with-registry-auth --compose-file docker-compose.yml ${env.STACK_NAME}"
|
|
|
|
}
|
|
|
|
}
|
2022-03-29 10:53:02 +00:00
|
|
|
}
|
2024-01-29 07:38:55 +00:00
|
|
|
}
|