2017-05-12 10:41:35 +00:00
|
|
|
#!/usr/bin/env groovy
|
|
|
|
|
2019-01-11 12:55:16 +00:00
|
|
|
pipeline {
|
2019-01-11 13:15:34 +00:00
|
|
|
agent any
|
2019-01-17 11:06:40 +00:00
|
|
|
options {
|
|
|
|
disableConcurrentBuilds()
|
|
|
|
}
|
2019-01-11 12:55:16 +00:00
|
|
|
environment {
|
|
|
|
REGISTRY = 'registry.verdnatura.es'
|
2019-02-11 22:49:38 +00:00
|
|
|
DOCKER_HOST_1 = 'vch1.verdnatura.es'
|
|
|
|
DOCKER_HOST_2 = 'vch2.verdnatura.es'
|
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:15:34 +00:00
|
|
|
stage('Checkout') {
|
2019-01-11 13:01:48 +00:00
|
|
|
steps {
|
2019-01-11 13:02:34 +00:00
|
|
|
script {
|
2019-02-13 13:01:37 +00:00
|
|
|
env.COMPOSE_PROJECT_NAME = env.JOB_NAME.replace('/', '-')
|
2019-01-11 14:36:04 +00:00
|
|
|
env.GIT_COMMITTER_EMAIL = sh(
|
2019-01-17 09:44:07 +00:00
|
|
|
script: 'git --no-pager show -s --format="%ae"',
|
2019-01-11 14:36:04 +00:00
|
|
|
returnStdout: true
|
|
|
|
).trim()
|
2019-01-11 13:02:34 +00:00
|
|
|
|
|
|
|
switch (env.BRANCH_NAME) {
|
|
|
|
case 'master':
|
|
|
|
env.PORT = 5002
|
2019-02-13 13:01:37 +00:00
|
|
|
break
|
|
|
|
case 'test':
|
2019-01-11 13:02:34 +00:00
|
|
|
env.PORT = 5001
|
2019-02-13 13:01:37 +00:00
|
|
|
break
|
|
|
|
case 'test':
|
|
|
|
env.PORT = 5000
|
|
|
|
break
|
2019-01-11 13:02:34 +00:00
|
|
|
}
|
|
|
|
switch (env.BRANCH_NAME) {
|
|
|
|
case 'master':
|
|
|
|
env.NODE_ENV = 'production'
|
2019-02-13 13:01:37 +00:00
|
|
|
break
|
|
|
|
case 'test':
|
2019-01-11 13:02:34 +00:00
|
|
|
env.NODE_ENV = 'test'
|
2019-02-13 13:01:37 +00:00
|
|
|
break
|
2019-01-11 13:02:34 +00:00
|
|
|
case 'dev':
|
|
|
|
env.NODE_ENV = 'development'
|
2019-02-13 13:01:37 +00:00
|
|
|
break
|
2019-01-11 13:02:34 +00:00
|
|
|
}
|
|
|
|
}
|
2019-01-11 13:01:48 +00:00
|
|
|
echo "Committer: ${env.GIT_COMMITTER_EMAIL}"
|
2019-01-11 12:55:16 +00:00
|
|
|
}
|
2018-10-24 12:10:41 +00:00
|
|
|
}
|
2019-02-11 23:22:59 +00:00
|
|
|
stage('Install') {
|
|
|
|
environment {
|
|
|
|
NODE_ENV = ""
|
|
|
|
}
|
2019-01-11 13:06:13 +00:00
|
|
|
steps {
|
|
|
|
nodejs('node-lts') {
|
2019-02-11 23:22:59 +00:00
|
|
|
sh 'npm install --no-audit'
|
|
|
|
sh 'gulp install'
|
2019-01-11 13:06:13 +00:00
|
|
|
}
|
2019-01-26 13:51:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
stage('Test') {
|
2019-02-01 08:44:00 +00:00
|
|
|
when {
|
2019-02-13 13:01:37 +00:00
|
|
|
branch 'dev'
|
2019-02-01 08:44:00 +00:00
|
|
|
}
|
2019-01-26 13:53:32 +00:00
|
|
|
environment {
|
2019-01-26 14:01:06 +00:00
|
|
|
NODE_ENV = ""
|
2019-01-26 19:26:14 +00:00
|
|
|
FIREFOX_BIN = "/opt/firefox/firefox-bin"
|
2019-02-11 22:01:32 +00:00
|
|
|
DB_HOST = "${env.DOCKER_HOST_2}"
|
2019-01-26 13:53:32 +00:00
|
|
|
}
|
2019-01-26 13:51:36 +00:00
|
|
|
steps {
|
2019-01-26 18:38:53 +00:00
|
|
|
nodejs('node-lts') {
|
2019-01-26 19:26:14 +00:00
|
|
|
sh 'karma start --junit'
|
2019-02-11 21:57:48 +00:00
|
|
|
sh 'gulp backTestDocker --junit --random --run-chown'
|
2019-01-26 18:38:53 +00:00
|
|
|
}
|
2019-01-26 13:51:36 +00:00
|
|
|
}
|
|
|
|
}
|
2019-02-11 23:24:08 +00:00
|
|
|
stage('Build') {
|
2019-02-01 08:44:00 +00:00
|
|
|
when {
|
|
|
|
not { branch 'dev' }
|
|
|
|
}
|
2019-01-26 13:51:36 +00:00
|
|
|
environment {
|
|
|
|
CREDS = credentials('docker-registry')
|
|
|
|
}
|
|
|
|
steps {
|
2019-02-11 23:22:59 +00:00
|
|
|
nodejs('node-lts') {
|
|
|
|
sh 'gulp build'
|
|
|
|
}
|
|
|
|
|
2019-01-11 13:06:13 +00:00
|
|
|
sh 'docker login --username $CREDS_USR --password $CREDS_PSW $REGISTRY'
|
2019-01-17 09:44:07 +00:00
|
|
|
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
|
|
|
}
|
2019-01-11 13:15:34 +00:00
|
|
|
stage('Deploy') {
|
2019-02-01 08:44:00 +00:00
|
|
|
when {
|
|
|
|
not { branch 'dev' }
|
|
|
|
}
|
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:15:34 +00:00
|
|
|
parallel {
|
|
|
|
stage('Host 1') {
|
|
|
|
environment {
|
2019-02-11 22:49:38 +00:00
|
|
|
DOCKER_HOST = "tcp://${env.DOCKER_HOST_1}:2376"
|
2019-01-11 13:15:34 +00:00
|
|
|
}
|
|
|
|
steps {
|
2019-01-11 13:40:13 +00:00
|
|
|
withCredentials([dockerCert(credentialsId: 'docker', variable: 'DOCKER_CERT_PATH')]) {
|
2019-01-17 09:44:07 +00:00
|
|
|
sh 'docker-compose pull'
|
2019-02-07 07:03:23 +00:00
|
|
|
sh 'docker-compose up -d --scale back=2'
|
2019-01-11 13:40:13 +00:00
|
|
|
}
|
2019-01-11 13:15:34 +00:00
|
|
|
}
|
2019-01-11 13:16:34 +00:00
|
|
|
}
|
2019-01-11 13:15:34 +00:00
|
|
|
stage('Host 2') {
|
|
|
|
environment {
|
2019-02-11 22:49:38 +00:00
|
|
|
DOCKER_HOST = "tcp://${env.DOCKER_HOST_2}:2376"
|
2019-01-11 13:15:34 +00:00
|
|
|
}
|
|
|
|
steps {
|
2019-01-11 13:40:13 +00:00
|
|
|
withCredentials([dockerCert(credentialsId: 'docker', variable: 'DOCKER_CERT_PATH')]) {
|
2019-01-17 09:44:07 +00:00
|
|
|
sh 'docker-compose pull'
|
2019-02-07 07:03:23 +00:00
|
|
|
sh 'docker-compose up -d --scale back=2'
|
2019-01-11 13:40:13 +00:00
|
|
|
}
|
2019-01-11 12:55:16 +00:00
|
|
|
}
|
2019-01-11 13:15:34 +00:00
|
|
|
}
|
2019-01-11 13:06:13 +00:00
|
|
|
}
|
2019-01-11 08:35:26 +00:00
|
|
|
}
|
2019-01-11 13:15:34 +00:00
|
|
|
stage('Cleanup') {
|
2019-02-01 08:44:00 +00:00
|
|
|
when {
|
|
|
|
not { branch 'dev' }
|
|
|
|
}
|
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 {
|
2019-02-11 22:49:38 +00:00
|
|
|
if (env.BRANCH_NAME == 'dev') {
|
2019-02-01 10:46:54 +00:00
|
|
|
junit '*/junitresults.xml'
|
2019-02-11 22:49:38 +00:00
|
|
|
junit 'junitresults.xml'
|
|
|
|
}
|
2019-02-01 10:46:54 +00:00
|
|
|
|
2019-01-11 13:51:01 +00:00
|
|
|
if (!env.GIT_COMMITTER_EMAIL) return
|
2019-01-16 15:05:43 +00:00
|
|
|
try {
|
|
|
|
mail(
|
|
|
|
to: env.GIT_COMMITTER_EMAIL,
|
|
|
|
subject: "Pipeline: ${env.JOB_NAME} (${env.BUILD_NUMBER}): ${currentBuild.currentResult}",
|
|
|
|
body: "Check status at ${env.BUILD_URL}"
|
|
|
|
)
|
|
|
|
} catch (e) {
|
|
|
|
echo e.toString()
|
|
|
|
}
|
2019-01-11 12:55:16 +00:00
|
|
|
}
|
|
|
|
}
|
2019-01-08 15:40:46 +00:00
|
|
|
}
|
2019-01-08 15:44:43 +00:00
|
|
|
}
|