salix/Jenkinsfile

57 lines
1.5 KiB
Groovy

#!/usr/bin/env groovy
switch (env.BRANCH_NAME) {
case 'test':
env.NODE_ENV = 'test'
break;
case 'master':
env.NODE_ENV = 'production'
break;
}
node {
stage ('Print environment variables') {
echo "Build number: ${env.BUILD_NUMBER}, Node environment: ${env.NODE_ENV}"
}
stage ('Checkout') {
checkout scm
}
stage ('Install Node dependencies') {
nodejs('node-lts') {
sh "npm install --only=prod"
sh "npm install --only=dev"
sh "gulp install"
}
}
stage ('Build project') {
nodejs('node-lts') {
sh "gulp build"
}
}
stage ('Docker deployment') {
withCredentials([dockerCert(credentialsId: 'docker', variable: 'DOCKER_CERT_PATH')]) {
env.COMPOSE_PROJECT_NAME = 'salix'
env.DOCKER_TLS_VERIFY = 1
if (env.BRANCH_NAME != 'master') {
env.COMPOSE_PROJECT_NAME = "${env.BRANCH_NAME}-salix"
}
switch (env.BRANCH_NAME) {
case 'master':
env.PORT = 5000
break;
case 'test':
env.PORT = 5001
break;
}
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"
}
}
}