157 lines
4.8 KiB
Groovy
157 lines
4.8 KiB
Groovy
#!/usr/bin/env groovy
|
|
|
|
pipeline {
|
|
agent any
|
|
options {
|
|
disableConcurrentBuilds()
|
|
}
|
|
environment {
|
|
PROJECT_NAME = 'salix'
|
|
REGISTRY = 'registry.verdnatura.es'
|
|
PORT_MASTER_FRONT = '5002'
|
|
PORT_MASTER_BACK = '3001'
|
|
PORT_TEST_FRONT = '5001'
|
|
PORT_TEST_BACK = '4001'
|
|
TAG = "${env.BRANCH_NAME}"
|
|
}
|
|
stages {
|
|
stage('Checkout') {
|
|
steps {
|
|
script {
|
|
env.STACK_NAME = "${env.PROJECT_NAME}-${env.BRANCH_NAME}"
|
|
|
|
if (!env.GIT_COMMITTER_EMAIL) {
|
|
env.COMMITTER_EMAIL = sh(
|
|
script: 'git --no-pager show -s --format="%ae"',
|
|
returnStdout: true
|
|
).trim()
|
|
} else {
|
|
env.COMMITTER_EMAIL = env.GIT_COMMITTER_EMAIL;
|
|
}
|
|
|
|
switch (env.BRANCH_NAME) {
|
|
case 'master':
|
|
env.PORT_FRONT = PORT_MASTER_FRONT
|
|
env.PORT_BACK = PORT_MASTER_BACK
|
|
break
|
|
case 'test':
|
|
env.PORT_FRONT = PORT_TEST_FRONT
|
|
env.PORT_BACK = PORT_TEST_BACK
|
|
break
|
|
}
|
|
switch (env.BRANCH_NAME) {
|
|
case 'master':
|
|
env.NODE_ENV = 'production'
|
|
break
|
|
case 'test':
|
|
env.NODE_ENV = 'test'
|
|
break
|
|
}
|
|
}
|
|
sh 'printenv'
|
|
}
|
|
}
|
|
stage('Install') {
|
|
environment {
|
|
NODE_ENV = ""
|
|
}
|
|
steps {
|
|
nodejs('node-lts') {
|
|
sh 'npm install --no-audit'
|
|
sh 'gulp install'
|
|
}
|
|
}
|
|
}
|
|
stage('Test') {
|
|
environment {
|
|
NODE_ENV = ""
|
|
}
|
|
parallel {
|
|
stage('Frontend') {
|
|
steps {
|
|
nodejs('node-lts') {
|
|
sh 'jest --ci --reporters=default --reporters=jest-junit --maxWorkers=1'
|
|
}
|
|
}
|
|
}
|
|
stage('Backend') {
|
|
steps {
|
|
nodejs('node-lts') {
|
|
sh 'gulp backTestDockerOnce --junit --random'
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
stage('Build') {
|
|
when { anyOf {
|
|
branch 'test'
|
|
branch 'master'
|
|
}}
|
|
environment {
|
|
CREDS = credentials('docker-registry')
|
|
}
|
|
steps {
|
|
nodejs('node-lts') {
|
|
sh 'gulp build'
|
|
}
|
|
|
|
sh 'docker login --username $CREDS_USR --password $CREDS_PSW $REGISTRY'
|
|
sh 'docker-compose build --parallel'
|
|
sh 'docker-compose push'
|
|
sh 'docker logout $REGISTRY'
|
|
}
|
|
}
|
|
stage('Deploy') {
|
|
when { anyOf {
|
|
branch 'test'
|
|
branch 'master'
|
|
}}
|
|
steps {
|
|
sh "docker stack deploy --compose-file docker-compose.yml ${env.STACK_NAME}"
|
|
}
|
|
}
|
|
stage('Database') {
|
|
when { anyOf {
|
|
branch 'test'
|
|
branch 'master'
|
|
}}
|
|
steps {
|
|
configFileProvider([
|
|
configFile(fileId: "config.${env.NODE_ENV}.ini",
|
|
variable: 'MYSQL_CONFIG')
|
|
]) {
|
|
sh 'cp "$MYSQL_CONFIG" db/config.$NODE_ENV.ini'
|
|
}
|
|
|
|
sh 'db/import-changes.sh -f $NODE_ENV'
|
|
}
|
|
}
|
|
}
|
|
post {
|
|
always {
|
|
script {
|
|
if (!['master', 'test'].contains(env.BRANCH_NAME)) {
|
|
try {
|
|
junit 'junitresults.xml'
|
|
junit 'junit.xml'
|
|
} catch (e) {
|
|
echo e.toString()
|
|
}
|
|
}
|
|
|
|
if (!env.COMMITTER_EMAIL) 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()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|