2017-05-12 10:41:35 +00:00
|
|
|
#!/usr/bin/env groovy
|
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()
|
|
|
|
}
|
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 {
|
2019-01-11 13:15:34 +00:00
|
|
|
stage('Checkout') {
|
2019-01-11 13:01:48 +00:00
|
|
|
steps {
|
2019-01-11 13:02:34 +00:00
|
|
|
script {
|
|
|
|
switch (env.BRANCH_NAME) {
|
|
|
|
case 'master':
|
|
|
|
env.NODE_ENV = 'production'
|
2020-11-30 18:20:52 +00:00
|
|
|
env.BACK_REPLICAS = 4
|
2019-02-13 13:01:37 +00:00
|
|
|
break
|
|
|
|
case 'test':
|
2019-01-11 13:02:34 +00:00
|
|
|
env.NODE_ENV = 'test'
|
2020-11-30 18:20:52 +00:00
|
|
|
env.BACK_REPLICAS = 2
|
2019-02-13 13:01:37 +00:00
|
|
|
break
|
2024-01-30 18:05:55 +00:00
|
|
|
case 'dev':
|
|
|
|
env.NODE_ENV = 'dev'
|
|
|
|
break
|
2019-01-11 13:02:34 +00:00
|
|
|
}
|
2024-01-30 17:52:31 +00:00
|
|
|
|
2024-01-30 17:54:41 +00:00
|
|
|
if (env.JOB_NAME.startsWith('gitea/'))
|
2024-01-30 17:52:31 +00:00
|
|
|
env.RUN_SOURCE = 'git'
|
2019-01-11 13:02:34 +00:00
|
|
|
}
|
2019-12-23 13:32:18 +00:00
|
|
|
|
|
|
|
configFileProvider([
|
2019-12-23 14:21:47 +00:00
|
|
|
configFile(fileId: "salix.groovy",
|
2019-12-23 15:29:25 +00:00
|
|
|
variable: 'GROOVY_FILE')
|
2019-12-23 13:32:18 +00:00
|
|
|
]) {
|
2019-12-23 15:29:25 +00:00
|
|
|
load env.GROOVY_FILE
|
2019-12-23 13:32:18 +00:00
|
|
|
}
|
2019-12-23 14:21:47 +00:00
|
|
|
|
2021-04-29 22:39:44 +00:00
|
|
|
setEnv()
|
2019-01-11 12:55:16 +00:00
|
|
|
}
|
2018-10-24 12:10:41 +00:00
|
|
|
}
|
2019-02-11 23:22:59 +00:00
|
|
|
stage('Install') {
|
|
|
|
environment {
|
|
|
|
NODE_ENV = ""
|
|
|
|
}
|
2019-01-11 13:06:13 +00:00
|
|
|
steps {
|
2023-06-08 08:25:25 +00:00
|
|
|
nodejs('node-v20') {
|
2022-05-13 08:52:05 +00:00
|
|
|
sh 'npm install --no-audit --prefer-offline'
|
2019-12-30 15:57:55 +00:00
|
|
|
sh 'gulp install --ci'
|
2019-01-11 13:06:13 +00:00
|
|
|
}
|
2019-01-26 13:51:36 +00:00
|
|
|
}
|
|
|
|
}
|
2022-05-12 14:18:08 +00:00
|
|
|
stage('Test') {
|
2024-01-30 17:52:31 +00:00
|
|
|
when {
|
|
|
|
environment name: 'RUN_SOURCE', value: 'git'
|
|
|
|
not { anyOf {
|
|
|
|
branch 'test'
|
|
|
|
branch 'master'
|
|
|
|
}}
|
|
|
|
}
|
2019-01-26 13:53:32 +00:00
|
|
|
environment {
|
2019-01-26 14:01:06 +00:00
|
|
|
NODE_ENV = ""
|
2023-04-28 17:53:13 +00:00
|
|
|
TZ = 'Europe/Madrid'
|
2019-01-26 13:53:32 +00:00
|
|
|
}
|
2022-05-12 14:18:08 +00:00
|
|
|
parallel {
|
2022-05-13 10:25:35 +00:00
|
|
|
stage('Frontend') {
|
2022-05-12 14:18:08 +00:00
|
|
|
steps {
|
2023-06-08 08:25:25 +00:00
|
|
|
nodejs('node-v20') {
|
2024-01-28 13:34:53 +00:00
|
|
|
sh 'jest --ci --reporters=default --reporters=jest-junit --maxWorkers=4'
|
2022-05-12 14:18:08 +00:00
|
|
|
}
|
|
|
|
}
|
2022-05-13 10:25:35 +00:00
|
|
|
}
|
2022-11-14 09:13:26 +00:00
|
|
|
stage('Backend') {
|
|
|
|
steps {
|
2023-06-08 08:25:25 +00:00
|
|
|
nodejs('node-v20') {
|
2022-11-14 09:13:26 +00:00
|
|
|
sh 'npm run test:back:ci'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-10-27 07:26:02 +00:00
|
|
|
}
|
2019-01-26 13:51:36 +00:00
|
|
|
}
|
2019-02-11 23:24:08 +00:00
|
|
|
stage('Build') {
|
2024-01-30 17:52:31 +00:00
|
|
|
when {
|
|
|
|
environment name: 'RUN_SOURCE', value: 'git'
|
|
|
|
anyOf {
|
|
|
|
branch 'test'
|
|
|
|
branch 'master'
|
|
|
|
}
|
|
|
|
}
|
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 {
|
2023-06-08 08:25:25 +00:00
|
|
|
nodejs('node-v20') {
|
2019-02-11 23:22:59 +00:00
|
|
|
sh 'gulp build'
|
|
|
|
}
|
|
|
|
|
2021-04-29 22:39:44 +00:00
|
|
|
dockerBuild()
|
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 17:52:31 +00:00
|
|
|
when {
|
|
|
|
environment name: 'RUN_SOURCE', value: 'git'
|
|
|
|
anyOf {
|
|
|
|
branch 'test'
|
|
|
|
branch 'master'
|
|
|
|
}
|
|
|
|
}
|
2021-04-29 22:39:44 +00:00
|
|
|
environment {
|
|
|
|
DOCKER_HOST = "${env.SWARM_HOST}"
|
|
|
|
}
|
2019-12-19 13:31:02 +00:00
|
|
|
steps {
|
2019-12-19 15:16:54 +00:00
|
|
|
sh "docker stack deploy --with-registry-auth --compose-file docker-compose.yml ${env.STACK_NAME}"
|
2019-01-11 13:06:13 +00:00
|
|
|
}
|
2019-01-11 08:35:26 +00:00
|
|
|
}
|
2019-03-20 11:21:32 +00:00
|
|
|
stage('Database') {
|
|
|
|
when { anyOf {
|
2024-01-30 09:00:35 +00:00
|
|
|
branch 'dev'
|
2019-03-20 11:21:32 +00:00
|
|
|
branch 'test'
|
2019-04-16 06:11:27 +00:00
|
|
|
branch 'master'
|
2019-03-20 11:21:32 +00:00
|
|
|
}}
|
|
|
|
steps {
|
|
|
|
configFileProvider([
|
2024-01-30 18:01:14 +00:00
|
|
|
configFile(fileId: "config.${env.NODE_ENV}.ini",
|
2019-03-20 11:21:32 +00:00
|
|
|
variable: 'MYSQL_CONFIG')
|
|
|
|
]) {
|
2024-01-28 11:40:13 +00:00
|
|
|
sh 'mkdir -p db/remotes'
|
|
|
|
sh 'cp "$MYSQL_CONFIG" db/remotes/$NODE_ENV.ini'
|
|
|
|
}
|
|
|
|
nodejs('node-v20') {
|
|
|
|
sh 'npx myt push $NODE_ENV --force --commit'
|
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 {
|
|
|
|
if (env.RUN_SOURCE == 'git'
|
|
|
|
&& ['master', 'test'].contains(env.BRANCH_NAME)) {
|
|
|
|
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
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-01-11 12:55:16 +00:00
|
|
|
always {
|
|
|
|
script {
|
2019-02-17 18:30:35 +00:00
|
|
|
if (!['master', 'test'].contains(env.BRANCH_NAME)) {
|
2019-02-15 12:32:07 +00:00
|
|
|
try {
|
2022-05-13 10:25:35 +00:00
|
|
|
junit 'junitresults.xml'
|
|
|
|
junit 'junit.xml'
|
2019-02-15 12:32:07 +00:00
|
|
|
} catch (e) {
|
|
|
|
echo e.toString()
|
|
|
|
}
|
2019-02-11 22:49:38 +00:00
|
|
|
}
|
2019-02-01 10:46:54 +00:00
|
|
|
|
2020-09-24 13:00:43 +00:00
|
|
|
if (!env.COMMITTER_EMAIL || currentBuild.currentResult == 'SUCCESS') return;
|
2019-01-16 15:05:43 +00:00
|
|
|
try {
|
|
|
|
mail(
|
2019-02-20 13:34:16 +00:00
|
|
|
to: env.COMMITTER_EMAIL,
|
2019-01-16 15:05:43 +00:00
|
|
|
subject: "Pipeline: ${env.JOB_NAME} (${env.BUILD_NUMBER}): ${currentBuild.currentResult}",
|
|
|
|
body: "Check status at ${env.BUILD_URL}"
|
|
|
|
)
|
|
|
|
} catch (e) {
|
|
|
|
echo e.toString()
|
|
|
|
}
|
2019-01-11 12:55:16 +00:00
|
|
|
}
|
|
|
|
}
|
2019-01-08 15:40:46 +00:00
|
|
|
}
|
2019-01-08 15:44:43 +00:00
|
|
|
}
|