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-08 13:01:04 +00:00
|
|
|
try {
|
2019-01-11 12:06:15 +00:00
|
|
|
def registry = 'registry.verdnatura.es'
|
|
|
|
env.COMPOSE_PROJECT_NAME = env.JOB_NAME.replace('/', '-');
|
|
|
|
env.TAG = env.BRANCH_NAME
|
|
|
|
|
2019-01-08 14:54:02 +00:00
|
|
|
switch (env.BRANCH_NAME) {
|
|
|
|
case 'master':
|
2019-01-11 12:06:15 +00:00
|
|
|
env.PORT = 5002
|
2019-01-08 14:54:02 +00:00
|
|
|
break;
|
|
|
|
case 'test':
|
2019-01-11 12:06:15 +00:00
|
|
|
env.PORT = 5001
|
2019-01-08 14:54:02 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-01-11 08:35:26 +00:00
|
|
|
switch (env.BRANCH_NAME) {
|
|
|
|
case 'master':
|
2019-01-11 12:06:15 +00:00
|
|
|
env.NODE_ENV = 'production'
|
2019-01-11 08:35:26 +00:00
|
|
|
break;
|
|
|
|
case 'test':
|
2019-01-11 12:06:15 +00:00
|
|
|
env.NODE_ENV = 'test'
|
|
|
|
break;
|
|
|
|
case 'dev':
|
|
|
|
env.NODE_ENV = 'development'
|
2019-01-11 08:35:26 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-01-08 13:01:04 +00:00
|
|
|
node {
|
|
|
|
stage ('Checkout') {
|
2019-01-08 15:51:48 +00:00
|
|
|
checkout scm
|
2019-01-08 16:29:02 +00:00
|
|
|
env.GIT_COMMITTER_EMAIL = sh(
|
2019-01-08 15:27:47 +00:00
|
|
|
script: "git --no-pager show -s --format='%ae'",
|
|
|
|
returnStdout: true
|
|
|
|
).trim()
|
2019-01-08 16:37:17 +00:00
|
|
|
echo "Committer: ${env.GIT_COMMITTER_EMAIL}"
|
2018-10-24 12:10:41 +00:00
|
|
|
}
|
2019-01-08 15:07:21 +00:00
|
|
|
stage ('Build') {
|
2019-01-08 15:52:59 +00:00
|
|
|
nodejs('node-lts') {
|
2019-01-11 08:39:39 +00:00
|
|
|
withEnv(['NODE_ENV=']) {
|
|
|
|
sh "npm install --no-audit"
|
|
|
|
sh "gulp install"
|
|
|
|
}
|
2019-01-08 13:01:04 +00:00
|
|
|
sh "gulp build"
|
2019-01-02 00:16:28 +00:00
|
|
|
}
|
2019-01-11 07:28:55 +00:00
|
|
|
|
|
|
|
withCredentials([usernamePassword(
|
|
|
|
credentialsId: 'docker-registry',
|
|
|
|
usernameVariable: 'USER',
|
|
|
|
passwordVariable: 'PASSWORD')
|
|
|
|
]) {
|
2019-01-11 12:06:15 +00:00
|
|
|
sh "docker login --username \$USER --password \$PASSWORD ${registry}"
|
2019-01-11 08:20:54 +00:00
|
|
|
}
|
2019-01-02 01:02:29 +00:00
|
|
|
|
2019-01-11 08:20:54 +00:00
|
|
|
sh "docker-compose build --parallel"
|
|
|
|
sh "docker-compose push"
|
2019-01-11 08:35:26 +00:00
|
|
|
}
|
|
|
|
stage ('Deploy') {
|
2019-01-11 08:24:45 +00:00
|
|
|
withEnv(['DOCKER_TLS_VERIFY=1']) {
|
|
|
|
withCredentials([dockerCert(
|
|
|
|
credentialsId: 'docker',
|
|
|
|
variable: 'DOCKER_CERT_PATH')
|
|
|
|
]) {
|
|
|
|
parallel(
|
|
|
|
vch1: {
|
|
|
|
withEnv(['DOCKER_HOST=tcp://vch1.verdnatura.es:2376']) {
|
|
|
|
sh "docker-compose pull"
|
|
|
|
sh "docker-compose up -d"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
vch2: {
|
|
|
|
withEnv(['DOCKER_HOST=tcp://vch2.verdnatura.es:2376']) {
|
|
|
|
sh "docker-compose pull"
|
|
|
|
sh "docker-compose up -d"
|
|
|
|
}
|
2019-01-11 08:20:54 +00:00
|
|
|
}
|
2019-01-11 08:24:45 +00:00
|
|
|
)
|
|
|
|
}
|
2019-01-08 13:01:04 +00:00
|
|
|
}
|
2019-01-11 08:35:26 +00:00
|
|
|
}
|
|
|
|
stage ('Cleanup') {
|
2019-01-11 08:20:54 +00:00
|
|
|
sh "docker logout ${registry}"
|
2019-01-01 22:43:00 +00:00
|
|
|
}
|
2018-10-24 12:41:38 +00:00
|
|
|
}
|
2019-01-08 13:01:04 +00:00
|
|
|
} catch(e) {
|
2019-01-08 16:07:03 +00:00
|
|
|
buildError = e
|
2019-01-08 15:40:46 +00:00
|
|
|
}
|
2019-01-08 16:07:03 +00:00
|
|
|
|
2019-01-08 15:47:36 +00:00
|
|
|
if (env.GIT_COMMITTER_EMAIL) {
|
2019-01-08 15:40:46 +00:00
|
|
|
def status
|
2019-01-08 16:07:03 +00:00
|
|
|
def body = "Check status at ${env.BUILD_URL}"
|
2019-01-08 15:40:46 +00:00
|
|
|
|
|
|
|
if (buildError) {
|
|
|
|
status = 'Failed'
|
2019-01-08 16:25:04 +00:00
|
|
|
body += "\n\nError: ${buildError.toString()}"
|
2019-01-08 15:40:46 +00:00
|
|
|
} else {
|
2019-01-08 15:44:43 +00:00
|
|
|
status = 'Success'
|
2019-01-08 15:40:46 +00:00
|
|
|
}
|
|
|
|
|
2019-01-08 16:17:12 +00:00
|
|
|
mail(
|
2019-01-08 15:47:36 +00:00
|
|
|
to: env.GIT_COMMITTER_EMAIL,
|
2019-01-08 15:40:46 +00:00
|
|
|
subject: "Pipeline: ${status}: ${env.JOB_NAME} (${env.BUILD_NUMBER})",
|
|
|
|
body: body
|
2019-01-08 15:00:25 +00:00
|
|
|
)
|
2019-01-08 15:44:43 +00:00
|
|
|
}
|
2019-01-08 16:22:55 +00:00
|
|
|
|
|
|
|
if (buildError)
|
|
|
|
throw buildError;
|