2017-05-12 10:41:35 +00:00
|
|
|
#!/usr/bin/env groovy
|
|
|
|
|
2019-01-08 15:44:43 +00:00
|
|
|
def buildError
|
2019-01-08 15:40:46 +00:00
|
|
|
|
2019-01-11 12:55:16 +00:00
|
|
|
pipeline {
|
|
|
|
environment {
|
|
|
|
REGISTRY = 'registry.verdnatura.es'
|
|
|
|
DOCKER_HOST_1 = 'tcp://vch1.verdnatura.es:2376'
|
|
|
|
DOCKER_HOST_2 = 'tcp://vch1.verdnatura.es:2376'
|
2019-01-11 12:57:07 +00:00
|
|
|
TAG = "${env.BRANCH_NAME}"
|
2019-01-08 14:54:02 +00:00
|
|
|
}
|
2019-01-11 12:55:16 +00:00
|
|
|
stages {
|
2019-01-11 13:01:02 +00:00
|
|
|
stage ('Checkout') {
|
2019-01-11 13:01:48 +00:00
|
|
|
steps {
|
2019-01-11 13:02:34 +00:00
|
|
|
script {
|
|
|
|
env.COMPOSE_PROJECT_NAME = env.JOB_NAME.replace('/', '-');
|
|
|
|
|
|
|
|
switch (env.BRANCH_NAME) {
|
|
|
|
case 'master':
|
|
|
|
env.PORT = 5002
|
|
|
|
break;
|
|
|
|
case 'test':
|
|
|
|
env.PORT = 5001
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2019-01-11 13:06:13 +00:00
|
|
|
|
2019-01-11 13:01:48 +00:00
|
|
|
checkout scm
|
|
|
|
script {
|
|
|
|
env.GIT_COMMITTER_EMAIL = sh(
|
|
|
|
script: "git --no-pager show -s --format='%ae'",
|
|
|
|
returnStdout: true
|
|
|
|
).trim()
|
|
|
|
}
|
|
|
|
echo "Committer: ${env.GIT_COMMITTER_EMAIL}"
|
2019-01-11 12:55:16 +00:00
|
|
|
}
|
2018-10-24 12:10:41 +00:00
|
|
|
}
|
2019-01-11 12:55:16 +00:00
|
|
|
stage ('Install') {
|
|
|
|
environment {
|
2019-01-11 12:57:07 +00:00
|
|
|
NODE_ENV = ''
|
2019-01-11 12:55:16 +00:00
|
|
|
}
|
2019-01-11 13:06:13 +00:00
|
|
|
steps {
|
|
|
|
nodejs('node-lts') {
|
|
|
|
sh "npm install --no-audit"
|
|
|
|
sh "gulp install"
|
|
|
|
}
|
2019-01-11 12:55:16 +00:00
|
|
|
}
|
|
|
|
}
|
2019-01-08 15:07:21 +00:00
|
|
|
stage ('Build') {
|
2019-01-11 12:55:16 +00:00
|
|
|
environment {
|
|
|
|
CREDS = credentials('docker-registry')
|
|
|
|
}
|
2019-01-11 13:06:13 +00:00
|
|
|
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"
|
2019-01-02 00:16:28 +00:00
|
|
|
}
|
2019-01-11 08:35:26 +00:00
|
|
|
}
|
|
|
|
stage ('Deploy') {
|
2019-01-11 12:55:16 +00:00
|
|
|
environment {
|
|
|
|
DOCKER_TLS_VERIFY = 1
|
2019-01-08 13:01:04 +00:00
|
|
|
}
|
2019-01-11 13:06:13 +00:00
|
|
|
steps {
|
|
|
|
parallel(
|
|
|
|
vch1: {
|
|
|
|
environment {
|
|
|
|
DOCKER_HOST = "${env.DOCKER_HOST_1}"
|
|
|
|
}
|
|
|
|
sh "docker-compose pull"
|
|
|
|
sh "docker-compose up -d"
|
|
|
|
},
|
|
|
|
vch2: {
|
|
|
|
environment {
|
|
|
|
DOCKER_HOST = "${env.DOCKER_HOST_2}"
|
|
|
|
}
|
|
|
|
sh "docker-compose pull"
|
|
|
|
sh "docker-compose up -d"
|
2019-01-11 12:55:16 +00:00
|
|
|
}
|
2019-01-11 13:06:13 +00:00
|
|
|
)
|
|
|
|
}
|
2019-01-11 08:35:26 +00:00
|
|
|
}
|
|
|
|
stage ('Cleanup') {
|
2019-01-11 13:06:13 +00:00
|
|
|
steps {
|
|
|
|
sh 'docker logout $REGISTRY'
|
|
|
|
}
|
2019-01-01 22:43:00 +00:00
|
|
|
}
|
2018-10-24 12:41:38 +00:00
|
|
|
}
|
2019-01-11 12:55:16 +00:00
|
|
|
post {
|
|
|
|
always {
|
|
|
|
script {
|
|
|
|
if (!env.GIT_COMMITTER_EMAIL)
|
|
|
|
return
|
2019-01-08 16:07:03 +00:00
|
|
|
|
2019-01-11 12:55:16 +00:00
|
|
|
mail(
|
|
|
|
to: env.GIT_COMMITTER_EMAIL,
|
|
|
|
subject: "Pipeline: ${env.JOB_NAME} (${env.BUILD_NUMBER}): ${currentBuild.result}",
|
|
|
|
body: "Check status at ${env.BUILD_URL}"
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2019-01-08 15:40:46 +00:00
|
|
|
}
|
2019-01-08 15:44:43 +00:00
|
|
|
}
|