salix/Jenkinsfile

65 lines
1.8 KiB
Groovy

#!/usr/bin/env groovy
node {
stage ('Checkout') {
checkout scm
}
stage ('Install Node dependencies') {
nodejs('node-lts') {
sh "NODE_ENV="" npm install --no-audit"
sh "gulp install"
}
}
stage ('Build project') {
nodejs('node-lts') {
sh "gulp build"
}
}
stage ('Docker deployment') {
withCredentials([dockerCert(credentialsId: 'docker', variable: 'DOCKER_CERT_PATH')]) {
if (env.BRANCH_NAME != 'master') {
env.COMPOSE_PROJECT_NAME = "${env.BRANCH_NAME}-${env.JOB_NAME}"
}
switch (env.BRANCH_NAME) {
case 'master':
env.NODE_ENV = 'production'
break;
case 'test':
env.NODE_ENV = 'test'
break;
case 'dev':
env.NODE_ENV = 'development'
break;
}
switch (env.BRANCH_NAME) {
case 'master':
env.PORT = 5000
break;
case 'test':
env.PORT = 5001
break;
}
env.COMPOSE_PROJECT_NAME = env.JOB_NAME
env.DOCKER_TLS_VERIFY = 1
env.TAG = env.NODE_ENV
env.DOCKER_HOST = 'tcp://vch1.verdnatura.es:2376';
sh "docker-compose up --build -d"
env.DOCKER_HOST = 'tcp://vch2.verdnatura.es:2376';
sh "docker-compose up --build -d"
}
}
}
post {
always {
mail to: 'salix@verdnatura.es', subject: 'Pipeline', "Pipeline success: ${env.JOB_NAME}"
}
failure {
mail to: 'salix@verdnatura.es', subject: 'Pipeline', "Pipeline failed: ${env.JOB_NAME}"
}
}