2017-05-12 10:41:35 +00:00
|
|
|
#!/usr/bin/env groovy
|
2024-01-30 20:49:58 +00:00
|
|
|
|
2024-02-01 21:06:30 +00:00
|
|
|
def PROTECTED_BRANCH
|
|
|
|
def FROM_GIT
|
|
|
|
def RUN_TESTS
|
2024-02-04 23:10:05 +00:00
|
|
|
def RUN_BUILD
|
2024-02-01 21:06:30 +00:00
|
|
|
|
2024-02-06 09:20:04 +00:00
|
|
|
node {
|
|
|
|
stage('Setup') {
|
|
|
|
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
|
|
|
|
}
|
2024-02-01 21:04:49 +00:00
|
|
|
|
2024-02-06 09:20:04 +00:00
|
|
|
PROTECTED_BRANCH = [
|
|
|
|
'dev',
|
|
|
|
'test',
|
|
|
|
'master'
|
|
|
|
].contains(env.BRANCH_NAME)
|
2024-02-01 21:04:49 +00:00
|
|
|
|
2024-02-06 09:20:04 +00:00
|
|
|
FROM_GIT = env.JOB_NAME.startsWith('gitea/')
|
|
|
|
RUN_TESTS = !PROTECTED_BRANCH && FROM_GIT
|
|
|
|
RUN_BUILD = PROTECTED_BRANCH && FROM_GIT
|
2024-02-01 20:35:28 +00:00
|
|
|
|
2024-02-06 09:20:04 +00:00
|
|
|
// Uncomment to enable debugging
|
|
|
|
// https://loopback.io/doc/en/lb3/Setting-debug-strings.html#debug-strings-reference
|
|
|
|
//env.DEBUG = 'strong-remoting:shared-method'
|
2024-02-06 09:38:11 +00:00
|
|
|
|
|
|
|
echo "Node: ${NODE_NAME}"
|
|
|
|
echo "Workspace: ${WORKSPACE}"
|
2024-02-06 09:20:04 +00:00
|
|
|
}
|
2024-02-01 21:13:36 +00:00
|
|
|
}
|
2019-01-11 12:55:16 +00:00
|
|
|
pipeline {
|
2019-01-11 13:15:34 +00:00
|
|
|
agent any
|
2019-01-17 11:06:40 +00:00
|
|
|
options {
|
|
|
|
disableConcurrentBuilds()
|
|
|
|
}
|
2024-02-01 13:07:42 +00:00
|
|
|
tools {
|
|
|
|
nodejs 'node-v20'
|
|
|
|
}
|
2019-01-11 12:55:16 +00:00
|
|
|
environment {
|
2019-12-23 13:33:54 +00:00
|
|
|
PROJECT_NAME = 'salix'
|
2024-01-30 17:52:31 +00:00
|
|
|
STACK_NAME = "${env.PROJECT_NAME}-${env.BRANCH_NAME}"
|
2019-01-08 14:54:02 +00:00
|
|
|
}
|
2019-01-11 12:55:16 +00:00
|
|
|
stages {
|
2024-02-06 09:20:04 +00:00
|
|
|
stage('Install') {
|
|
|
|
environment {
|
|
|
|
NODE_ENV = ''
|
|
|
|
}
|
|
|
|
parallel {
|
|
|
|
stage('Back') {
|
|
|
|
steps {
|
|
|
|
sh 'pnpm install --prefer-offline'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
stage('Print') {
|
|
|
|
when {
|
|
|
|
expression { FROM_GIT }
|
|
|
|
}
|
|
|
|
steps {
|
|
|
|
sh 'pnpm install --prefer-offline --prefix=print'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
stage('Front') {
|
|
|
|
when {
|
|
|
|
expression { FROM_GIT }
|
|
|
|
}
|
|
|
|
steps {
|
|
|
|
sh 'pnpm install --prefer-offline --prefix=front'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-02-04 20:09:49 +00:00
|
|
|
stage('Stack') {
|
2019-02-11 23:22:59 +00:00
|
|
|
environment {
|
2024-02-04 20:00:03 +00:00
|
|
|
TZ = 'Europe/Madrid'
|
2019-02-11 23:22:59 +00:00
|
|
|
}
|
2024-01-30 19:04:32 +00:00
|
|
|
parallel {
|
2024-02-04 22:58:26 +00:00
|
|
|
stage('Back') {
|
2024-02-04 20:17:47 +00:00
|
|
|
stages {
|
|
|
|
stage('Test') {
|
|
|
|
when {
|
|
|
|
expression { RUN_TESTS }
|
|
|
|
}
|
|
|
|
environment {
|
2024-02-06 09:20:04 +00:00
|
|
|
NODE_ENV = ''
|
2024-02-04 20:17:47 +00:00
|
|
|
}
|
|
|
|
steps {
|
|
|
|
sh 'npm run test:back:ci'
|
|
|
|
}
|
|
|
|
post {
|
|
|
|
always {
|
|
|
|
script {
|
|
|
|
try {
|
|
|
|
junit 'junitresults.xml'
|
|
|
|
junit 'junit.xml'
|
|
|
|
} catch (e) {
|
|
|
|
echo e.toString()
|
|
|
|
}
|
2024-02-04 20:00:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-02-04 20:17:47 +00:00
|
|
|
stage('Build') {
|
|
|
|
when {
|
|
|
|
expression { RUN_BUILD }
|
|
|
|
}
|
|
|
|
steps {
|
2024-02-05 10:38:16 +00:00
|
|
|
script {
|
|
|
|
def packageJson = readJSON file: 'package.json'
|
|
|
|
env.VERSION = packageJson.version
|
|
|
|
}
|
2024-02-04 20:17:47 +00:00
|
|
|
sh 'docker-compose build back'
|
|
|
|
}
|
2024-02-04 20:00:03 +00:00
|
|
|
}
|
2024-01-30 20:57:04 +00:00
|
|
|
}
|
2024-02-04 20:17:47 +00:00
|
|
|
}
|
2024-02-04 22:58:26 +00:00
|
|
|
stage('Front') {
|
2024-02-04 20:17:47 +00:00
|
|
|
when {
|
|
|
|
expression { FROM_GIT }
|
2024-01-30 19:04:32 +00:00
|
|
|
}
|
2024-02-04 20:17:47 +00:00
|
|
|
stages {
|
|
|
|
stage('Test') {
|
|
|
|
when {
|
|
|
|
expression { RUN_TESTS }
|
|
|
|
}
|
|
|
|
environment {
|
2024-02-06 09:20:04 +00:00
|
|
|
NODE_ENV = ''
|
2024-02-04 20:17:47 +00:00
|
|
|
}
|
|
|
|
steps {
|
|
|
|
sh 'jest --ci --reporters=default --reporters=jest-junit --maxWorkers=10'
|
|
|
|
}
|
2024-02-04 20:00:03 +00:00
|
|
|
}
|
2024-02-04 20:17:47 +00:00
|
|
|
stage('Build') {
|
|
|
|
when {
|
|
|
|
expression { RUN_BUILD }
|
|
|
|
}
|
|
|
|
steps {
|
2024-02-05 10:38:16 +00:00
|
|
|
script {
|
|
|
|
def packageJson = readJSON file: 'package.json'
|
|
|
|
env.VERSION = packageJson.version
|
|
|
|
}
|
2024-02-04 20:17:47 +00:00
|
|
|
sh 'gulp build'
|
|
|
|
sh 'docker-compose build front'
|
|
|
|
}
|
2024-02-04 20:00:03 +00:00
|
|
|
}
|
2022-11-14 09:13:26 +00:00
|
|
|
}
|
2024-02-04 20:17:47 +00:00
|
|
|
}
|
2022-10-27 07:26:02 +00:00
|
|
|
}
|
2019-01-26 13:51:36 +00:00
|
|
|
}
|
2024-02-04 20:09:49 +00:00
|
|
|
stage('Push') {
|
2024-01-30 17:52:31 +00:00
|
|
|
when {
|
2024-02-04 20:00:03 +00:00
|
|
|
expression { RUN_BUILD }
|
2024-01-30 17:52:31 +00:00
|
|
|
}
|
2019-01-26 13:51:36 +00:00
|
|
|
environment {
|
2021-04-29 22:39:44 +00:00
|
|
|
CREDENTIALS = credentials('docker-registry')
|
2019-01-26 13:51:36 +00:00
|
|
|
}
|
|
|
|
steps {
|
2024-02-02 13:27:36 +00:00
|
|
|
script {
|
|
|
|
def packageJson = readJSON file: 'package.json'
|
|
|
|
env.VERSION = packageJson.version
|
|
|
|
}
|
2024-02-04 20:09:49 +00:00
|
|
|
sh 'docker login --username $CREDENTIALS_USR --password $CREDENTIALS_PSW $REGISTRY'
|
|
|
|
sh 'docker-compose push'
|
2019-01-02 00:16:28 +00:00
|
|
|
}
|
2019-01-11 08:35:26 +00:00
|
|
|
}
|
2019-01-11 13:15:34 +00:00
|
|
|
stage('Deploy') {
|
2024-01-30 19:58:15 +00:00
|
|
|
when {
|
2024-02-01 20:49:42 +00:00
|
|
|
expression { PROTECTED_BRANCH }
|
2024-01-30 19:58:15 +00:00
|
|
|
}
|
2024-01-30 18:51:30 +00:00
|
|
|
parallel {
|
|
|
|
stage('Database') {
|
|
|
|
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'
|
|
|
|
}
|
2024-01-30 20:37:20 +00:00
|
|
|
|
|
|
|
sh 'npx myt push $NODE_ENV --force --commit'
|
2024-01-30 18:51:30 +00:00
|
|
|
}
|
2019-03-20 11:21:32 +00:00
|
|
|
}
|
2024-01-30 19:04:32 +00:00
|
|
|
stage('Docker') {
|
|
|
|
when {
|
2024-02-01 20:49:42 +00:00
|
|
|
expression { FROM_GIT }
|
2024-01-30 19:04:32 +00:00
|
|
|
}
|
|
|
|
environment {
|
|
|
|
DOCKER_HOST = "${env.SWARM_HOST}"
|
|
|
|
}
|
|
|
|
steps {
|
2024-02-02 13:27:36 +00:00
|
|
|
script {
|
|
|
|
def packageJson = readJSON file: 'package.json'
|
|
|
|
env.VERSION = packageJson.version
|
|
|
|
}
|
2024-01-30 19:04:32 +00:00
|
|
|
sh "docker stack deploy --with-registry-auth --compose-file docker-compose.yml ${env.STACK_NAME}"
|
|
|
|
}
|
|
|
|
}
|
2019-03-20 11:21:32 +00:00
|
|
|
}
|
|
|
|
}
|
2018-10-24 12:41:38 +00:00
|
|
|
}
|
2019-01-11 12:55:16 +00:00
|
|
|
post {
|
2024-01-30 17:52:31 +00:00
|
|
|
success {
|
|
|
|
script {
|
2024-01-30 20:49:58 +00:00
|
|
|
if (env.BRANCH_NAME == 'master' && FROM_GIT) {
|
2024-02-02 13:27:36 +00:00
|
|
|
env.GIT_COMMIT_MSG = sh(
|
|
|
|
script: 'git log -1 --pretty=%B ${GIT_COMMIT}',
|
|
|
|
returnStdout: true
|
|
|
|
).trim()
|
|
|
|
|
2024-01-30 17:52:31 +00:00
|
|
|
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
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-01-30 19:58:15 +00:00
|
|
|
unsuccessful {
|
2024-02-02 13:27:36 +00:00
|
|
|
setEnv()
|
2024-01-30 19:58:15 +00:00
|
|
|
sendEmail()
|
|
|
|
}
|
2019-01-08 15:40:46 +00:00
|
|
|
}
|
2019-01-08 15:44:43 +00:00
|
|
|
}
|