From b6c1fd2e8e0e1ee205b9d3a301b44f828e58456f Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Fri, 11 Jan 2019 08:28:55 +0100 Subject: [PATCH 01/25] Docker deploy with private registry --- Jenkinsfile | 42 +++++++++++++++++++++++++++++------------- docker-compose.yml | 8 ++++---- 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 10f78ee78..f2838a43a 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -32,25 +32,41 @@ try { } } stage ('Deploy') { - withCredentials([dockerCert(credentialsId: 'docker', variable: 'DOCKER_CERT_PATH')]) { - switch (env.BRANCH_NAME) { - case 'master': - env.PORT = 5000 - break; - case 'test': - env.PORT = 5001 - break; - } + env.COMPOSE_PROJECT_NAME = env.JOB_NAME.replace('/', '-'); + env.TAG = env.BRANCH_NAME - env.COMPOSE_PROJECT_NAME = env.JOB_NAME.replace('/', '-'); + switch (env.BRANCH_NAME) { + case 'master': + env.PORT = 5002 + break; + case 'test': + env.PORT = 5001 + break; + } + + withCredentials([usernamePassword( + credentialsId: 'docker-registry', + usernameVariable: 'USER', + passwordVariable: 'PASSWORD') + ]) { + env.REGISTRY = 'registry.verdnatura.es' + sh "docker login --username \"${env.USER}\" --password \"${env.PASSWORD}\" ${env.REGISTRY}" + sh "docker-compose build --parallel" + sh "docker-compose push" + sh "docker logout ${env.REGISTRY}" + } + + withCredentials([dockerCert( + credentialsId: 'docker', + variable: 'DOCKER_CERT_PATH') + ]) { env.DOCKER_TLS_VERIFY = 1 - env.TAG = env.BRANCH_NAME env.DOCKER_HOST = 'tcp://vch1.verdnatura.es:2376'; - sh "docker-compose up --build -d" + sh "docker-compose up -d" env.DOCKER_HOST = 'tcp://vch2.verdnatura.es:2376'; - sh "docker-compose up --build -d" + sh "docker-compose up -d" } } } diff --git a/docker-compose.yml b/docker-compose.yml index 9787368aa..317557eb2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,20 +1,20 @@ version: '3.5' services: app: + image: registry.verdnatura.es/salix-app:${TAG} + restart: unless-stopped build: context: . dockerfile: services/nginx/Dockerfile ports: - ${PORT}:80 - image: salix-app:${TAG} - restart: unless-stopped links: - api api: + image: registry.verdnatura.es/salix-api:${TAG} + restart: unless-stopped build: . environment: - NODE_ENV - restart: unless-stopped - image: salix-api:${TAG} volumes: - /containers/salix:/etc/salix From 5334a13e6634de19028eee7dbd8145300e1713ea Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Fri, 11 Jan 2019 08:46:21 +0100 Subject: [PATCH 02/25] Deploy with docker registry fixes --- Jenkinsfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index f2838a43a..94cdae728 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -63,9 +63,11 @@ try { env.DOCKER_TLS_VERIFY = 1 env.DOCKER_HOST = 'tcp://vch1.verdnatura.es:2376'; + sh "docker-compose pull" sh "docker-compose up -d" env.DOCKER_HOST = 'tcp://vch2.verdnatura.es:2376'; + sh "docker-compose pull" sh "docker-compose up -d" } } From eb0c497d055247786ce26b752d09ded699627b17 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Fri, 11 Jan 2019 08:56:31 +0100 Subject: [PATCH 03/25] Fixes for docker deploy with private registry --- Jenkinsfile | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 94cdae728..d51361c7a 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -54,21 +54,21 @@ try { sh "docker-compose build --parallel" sh "docker-compose push" sh "docker logout ${env.REGISTRY}" - } - withCredentials([dockerCert( - credentialsId: 'docker', - variable: 'DOCKER_CERT_PATH') - ]) { - env.DOCKER_TLS_VERIFY = 1 + withCredentials([dockerCert( + credentialsId: 'docker', + variable: 'DOCKER_CERT_PATH') + ]) { + env.DOCKER_TLS_VERIFY = 1 - env.DOCKER_HOST = 'tcp://vch1.verdnatura.es:2376'; - sh "docker-compose pull" - sh "docker-compose up -d" + env.DOCKER_HOST = 'tcp://vch1.verdnatura.es:2376'; + sh "docker-compose pull" + sh "docker-compose up -d" - env.DOCKER_HOST = 'tcp://vch2.verdnatura.es:2376'; - sh "docker-compose pull" - sh "docker-compose up -d" + env.DOCKER_HOST = 'tcp://vch2.verdnatura.es:2376'; + sh "docker-compose pull" + sh "docker-compose up -d" + } } } } From 26a461429636d1fd27647ea4b58da67305977e7c Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Fri, 11 Jan 2019 08:58:51 +0100 Subject: [PATCH 04/25] Deploy fixes --- Jenkinsfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index d51361c7a..0246d9863 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -53,7 +53,6 @@ try { sh "docker login --username \"${env.USER}\" --password \"${env.PASSWORD}\" ${env.REGISTRY}" sh "docker-compose build --parallel" sh "docker-compose push" - sh "docker logout ${env.REGISTRY}" withCredentials([dockerCert( credentialsId: 'docker', @@ -69,6 +68,8 @@ try { sh "docker-compose pull" sh "docker-compose up -d" } + + sh "docker logout ${env.REGISTRY}" } } } From 9d97b9be35ce30da284c603f907e3077f8ad1e3c Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Fri, 11 Jan 2019 09:20:54 +0100 Subject: [PATCH 05/25] Deploy test --- Jenkinsfile | 50 +++++++++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 0246d9863..b9cd8f186 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -33,6 +33,7 @@ try { } stage ('Deploy') { env.COMPOSE_PROJECT_NAME = env.JOB_NAME.replace('/', '-'); + env.DOCKER_TLS_VERIFY = 1; env.TAG = env.BRANCH_NAME switch (env.BRANCH_NAME) { @@ -43,34 +44,41 @@ try { env.PORT = 5001 break; } + + def registry = 'registry.verdnatura.es' withCredentials([usernamePassword( credentialsId: 'docker-registry', usernameVariable: 'USER', passwordVariable: 'PASSWORD') ]) { - env.REGISTRY = 'registry.verdnatura.es' - sh "docker login --username \"${env.USER}\" --password \"${env.PASSWORD}\" ${env.REGISTRY}" - sh "docker-compose build --parallel" - sh "docker-compose push" - - withCredentials([dockerCert( - credentialsId: 'docker', - variable: 'DOCKER_CERT_PATH') - ]) { - env.DOCKER_TLS_VERIFY = 1 - - env.DOCKER_HOST = 'tcp://vch1.verdnatura.es:2376'; - sh "docker-compose pull" - sh "docker-compose up -d" - - env.DOCKER_HOST = 'tcp://vch2.verdnatura.es:2376'; - sh "docker-compose pull" - sh "docker-compose up -d" - } - - sh "docker logout ${env.REGISTRY}" + sh "docker login --username \"${env.USER}\" --password \"${env.PASSWORD}\" ${registry}" } + + sh "docker-compose build --parallel" + sh "docker-compose push" + + 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" + } + } + ) + } + + sh "docker logout ${registry}" } } } catch(e) { From 8a035d5fab0df48b8b99bd17266c6b359320b314 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Fri, 11 Jan 2019 09:24:45 +0100 Subject: [PATCH 06/25] Deploy fixes --- Jenkinsfile | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index b9cd8f186..f67b9166f 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -33,7 +33,6 @@ try { } stage ('Deploy') { env.COMPOSE_PROJECT_NAME = env.JOB_NAME.replace('/', '-'); - env.DOCKER_TLS_VERIFY = 1; env.TAG = env.BRANCH_NAME switch (env.BRANCH_NAME) { @@ -58,24 +57,26 @@ try { sh "docker-compose build --parallel" sh "docker-compose push" - 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" + 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" + } } - }, - vch2: { - withEnv(['DOCKER_HOST=tcp://vch2.verdnatura.es:2376']) { - sh "docker-compose pull" - sh "docker-compose up -d" - } - } - ) + ) + } } sh "docker logout ${registry}" From f529cbb7e9ab8693cf96cd5a8b6a518e27fe5100 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Fri, 11 Jan 2019 09:35:26 +0100 Subject: [PATCH 07/25] Deploy fixes --- Jenkinsfile | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index f67b9166f..aacb5618a 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -15,6 +15,19 @@ try { break; } + def registry = 'registry.verdnatura.es' + env.COMPOSE_PROJECT_NAME = env.JOB_NAME.replace('/', '-'); + env.TAG = env.BRANCH_NAME + + switch (env.BRANCH_NAME) { + case 'master': + env.PORT = 5002 + break; + case 'test': + env.PORT = 5001 + break; + } + node { stage ('Checkout') { checkout scm @@ -30,21 +43,6 @@ try { sh "gulp install" sh "gulp build" } - } - stage ('Deploy') { - env.COMPOSE_PROJECT_NAME = env.JOB_NAME.replace('/', '-'); - env.TAG = env.BRANCH_NAME - - switch (env.BRANCH_NAME) { - case 'master': - env.PORT = 5002 - break; - case 'test': - env.PORT = 5001 - break; - } - - def registry = 'registry.verdnatura.es' withCredentials([usernamePassword( credentialsId: 'docker-registry', @@ -56,7 +54,8 @@ try { sh "docker-compose build --parallel" sh "docker-compose push" - + } + stage ('Deploy') { withEnv(['DOCKER_TLS_VERIFY=1']) { withCredentials([dockerCert( credentialsId: 'docker', @@ -78,7 +77,8 @@ try { ) } } - + } + stage ('Cleanup') { sh "docker logout ${registry}" } } From 776aa089df53c70eac59bff95efb2f537e981689 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Fri, 11 Jan 2019 09:39:39 +0100 Subject: [PATCH 08/25] Deploy improvements --- Jenkinsfile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index aacb5618a..a048826f9 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -39,8 +39,10 @@ try { } stage ('Build') { nodejs('node-lts') { - sh "env NODE_ENV= npm install --no-audit" - sh "gulp install" + withEnv(['NODE_ENV=']) { + sh "npm install --no-audit" + sh "gulp install" + } sh "gulp build" } From c5b3c5d191c08f52b9c9fa92da95d5f479d141c4 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Fri, 11 Jan 2019 13:06:15 +0100 Subject: [PATCH 09/25] Jenkinsfile refactor --- Jenkinsfile | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index a048826f9..acacfaa0c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -3,18 +3,6 @@ def buildError try { - 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; - } - def registry = 'registry.verdnatura.es' env.COMPOSE_PROJECT_NAME = env.JOB_NAME.replace('/', '-'); env.TAG = env.BRANCH_NAME @@ -28,6 +16,18 @@ try { 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; + } + node { stage ('Checkout') { checkout scm @@ -51,7 +51,7 @@ try { usernameVariable: 'USER', passwordVariable: 'PASSWORD') ]) { - sh "docker login --username \"${env.USER}\" --password \"${env.PASSWORD}\" ${registry}" + sh "docker login --username \$USER --password \$PASSWORD ${registry}" } sh "docker-compose build --parallel" From 59bfff22e48bb09c6f8d6899c8310af355e9a658 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Fri, 11 Jan 2019 13:55:16 +0100 Subject: [PATCH 10/25] Declarative Jenkinsfile --- Jenkinsfile | 163 +++++++++++++++++++++++++--------------------------- 1 file changed, 79 insertions(+), 84 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index acacfaa0c..40399b1a3 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -2,109 +2,104 @@ def buildError -try { - def registry = 'registry.verdnatura.es' - env.COMPOSE_PROJECT_NAME = env.JOB_NAME.replace('/', '-'); - env.TAG = env.BRANCH_NAME - - switch (env.BRANCH_NAME) { - case 'master': - env.PORT = 5002 - break; - case 'test': - env.PORT = 5001 - break; +pipeline { + environment { + REGISTRY = 'registry.verdnatura.es' + DOCKER_HOST_1 = 'tcp://vch1.verdnatura.es:2376' + DOCKER_HOST_2 = 'tcp://vch1.verdnatura.es:2376' + TAG = env.BRANCH_NAME } + script { + env.COMPOSE_PROJECT_NAME = env.JOB_NAME.replace('/', '-'); - 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 = 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; + } } - - node { + stages { stage ('Checkout') { checkout scm - env.GIT_COMMITTER_EMAIL = sh( - script: "git --no-pager show -s --format='%ae'", - returnStdout: true - ).trim() + script { + env.GIT_COMMITTER_EMAIL = sh( + script: "git --no-pager show -s --format='%ae'", + returnStdout: true + ).trim() + } echo "Committer: ${env.GIT_COMMITTER_EMAIL}" } - stage ('Build') { + stage ('Install') { + environment { + NODE_ENV = null + } + nodejs('node-lts') { + sh "npm install --no-audit" + sh "gulp install" + } + } + stage ('Build') { + environment { + CREDS = credentials('docker-registry') + } nodejs('node-lts') { - withEnv(['NODE_ENV=']) { - sh "npm install --no-audit" - sh "gulp install" - } sh "gulp build" } - - withCredentials([usernamePassword( - credentialsId: 'docker-registry', - usernameVariable: 'USER', - passwordVariable: 'PASSWORD') - ]) { - sh "docker login --username \$USER --password \$PASSWORD ${registry}" - } - + sh 'docker login --username $CREDS_USR --password $CREDS_PSW $REGISTRY' sh "docker-compose build --parallel" sh "docker-compose push" } stage ('Deploy') { - 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" - } - } - ) - } + environment { + DOCKER_TLS_VERIFY = 1 } + 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" + } + ) } stage ('Cleanup') { - sh "docker logout ${registry}" + sh 'docker logout $REGISTRY' } } -} catch(e) { - buildError = e -} + post { + always { + script { + if (!env.GIT_COMMITTER_EMAIL) + return -if (env.GIT_COMMITTER_EMAIL) { - def status - def body = "Check status at ${env.BUILD_URL}" - - if (buildError) { - status = 'Failed' - body += "\n\nError: ${buildError.toString()}" - } else { - status = 'Success' + mail( + to: env.GIT_COMMITTER_EMAIL, + subject: "Pipeline: ${env.JOB_NAME} (${env.BUILD_NUMBER}): ${currentBuild.result}", + body: "Check status at ${env.BUILD_URL}" + ) + } + } } - - mail( - to: env.GIT_COMMITTER_EMAIL, - subject: "Pipeline: ${status}: ${env.JOB_NAME} (${env.BUILD_NUMBER})", - body: body - ) } - -if (buildError) - throw buildError; From 27cc8ba2b1c2f99540201864368704a6b535405c Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Fri, 11 Jan 2019 13:57:07 +0100 Subject: [PATCH 11/25] Jenkinsfile fixes --- Jenkinsfile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 40399b1a3..580cf647b 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -7,7 +7,7 @@ pipeline { REGISTRY = 'registry.verdnatura.es' DOCKER_HOST_1 = 'tcp://vch1.verdnatura.es:2376' DOCKER_HOST_2 = 'tcp://vch1.verdnatura.es:2376' - TAG = env.BRANCH_NAME + TAG = "${env.BRANCH_NAME}" } script { env.COMPOSE_PROJECT_NAME = env.JOB_NAME.replace('/', '-'); @@ -45,7 +45,7 @@ pipeline { } stage ('Install') { environment { - NODE_ENV = null + NODE_ENV = '' } nodejs('node-lts') { sh "npm install --no-audit" @@ -70,14 +70,14 @@ pipeline { parallel( vch1: { environment { - DOCKER_HOST = env.DOCKER_HOST_1 + DOCKER_HOST = "${env.DOCKER_HOST_1}" } sh "docker-compose pull" sh "docker-compose up -d" }, vch2: { environment { - DOCKER_HOST = env.DOCKER_HOST_2 + DOCKER_HOST = "${env.DOCKER_HOST_2}" } sh "docker-compose pull" sh "docker-compose up -d" From bd90f302bf313deb26e0c7dc6b789b6154f83753 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Fri, 11 Jan 2019 13:58:52 +0100 Subject: [PATCH 12/25] Jenkinsfile fixes --- Jenkinsfile | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 580cf647b..1bf3a1258 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -9,31 +9,31 @@ pipeline { DOCKER_HOST_2 = 'tcp://vch1.verdnatura.es:2376' TAG = "${env.BRANCH_NAME}" } - 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; - } - } stages { stage ('Checkout') { + 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; + } + } checkout scm script { env.GIT_COMMITTER_EMAIL = sh( From b8b78f95179bdd6675e450b714df6323b1895690 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Fri, 11 Jan 2019 14:01:02 +0100 Subject: [PATCH 13/25] Jenkinsfile fix --- Jenkinsfile | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 1bf3a1258..3b72ff637 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -10,30 +10,30 @@ pipeline { TAG = "${env.BRANCH_NAME}" } stages { - stage ('Checkout') { - script { - env.COMPOSE_PROJECT_NAME = env.JOB_NAME.replace('/', '-'); + 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; - } + 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; + } + } + stage ('Checkout') { checkout scm script { env.GIT_COMMITTER_EMAIL = sh( From 064ed4bd8045f14dc6e78e44fecc0cc960432717 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Fri, 11 Jan 2019 14:01:48 +0100 Subject: [PATCH 14/25] Jenkinsfile fixes --- Jenkinsfile | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 3b72ff637..27fe8ea69 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -34,14 +34,16 @@ pipeline { } } stage ('Checkout') { - checkout scm - script { - env.GIT_COMMITTER_EMAIL = sh( - script: "git --no-pager show -s --format='%ae'", - returnStdout: true - ).trim() + steps { + 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}" } - echo "Committer: ${env.GIT_COMMITTER_EMAIL}" } stage ('Install') { environment { From eb3aa84fc582f52dbb3b37bc6f7b3da647cca3d2 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Fri, 11 Jan 2019 14:02:34 +0100 Subject: [PATCH 15/25] Jenkinsfile fixes --- Jenkinsfile | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 27fe8ea69..42aeb2de1 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -10,31 +10,31 @@ pipeline { TAG = "${env.BRANCH_NAME}" } stages { - 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; - } - } stage ('Checkout') { steps { + 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; + } + } checkout scm script { env.GIT_COMMITTER_EMAIL = sh( From 1e63adbdcac8b935b82766ec71b70b679a952c76 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Fri, 11 Jan 2019 14:06:13 +0100 Subject: [PATCH 16/25] Jenkinsfile fixes --- Jenkinsfile | 57 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 24 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 42aeb2de1..b37866d65 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -35,6 +35,7 @@ pipeline { break; } } + checkout scm script { env.GIT_COMMITTER_EMAIL = sh( @@ -49,45 +50,53 @@ pipeline { environment { NODE_ENV = '' } - nodejs('node-lts') { - sh "npm install --no-audit" - sh "gulp install" + steps { + nodejs('node-lts') { + sh "npm install --no-audit" + sh "gulp install" + } } } stage ('Build') { environment { CREDS = credentials('docker-registry') } - nodejs('node-lts') { - sh "gulp build" + 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" } - sh 'docker login --username $CREDS_USR --password $CREDS_PSW $REGISTRY' - sh "docker-compose build --parallel" - sh "docker-compose push" } stage ('Deploy') { environment { DOCKER_TLS_VERIFY = 1 } - parallel( - vch1: { - environment { - DOCKER_HOST = "${env.DOCKER_HOST_1}" + 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" } - 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" - } - ) + ) + } } stage ('Cleanup') { - sh 'docker logout $REGISTRY' + steps { + sh 'docker logout $REGISTRY' + } } } post { From 1b2e5e491c41c5cb20c8f0ff7a58c47d08dafbd8 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Fri, 11 Jan 2019 14:15:34 +0100 Subject: [PATCH 17/25] Jenkinsfile fixes --- Jenkinsfile | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index b37866d65..3ad377aa1 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -3,6 +3,7 @@ def buildError pipeline { + agent any environment { REGISTRY = 'registry.verdnatura.es' DOCKER_HOST_1 = 'tcp://vch1.verdnatura.es:2376' @@ -10,7 +11,7 @@ pipeline { TAG = "${env.BRANCH_NAME}" } stages { - stage ('Checkout') { + stage('Checkout') { steps { script { env.COMPOSE_PROJECT_NAME = env.JOB_NAME.replace('/', '-'); @@ -46,7 +47,7 @@ pipeline { echo "Committer: ${env.GIT_COMMITTER_EMAIL}" } } - stage ('Install') { + stage('Install') { environment { NODE_ENV = '' } @@ -57,7 +58,7 @@ pipeline { } } } - stage ('Build') { + stage('Build') { environment { CREDS = credentials('docker-registry') } @@ -70,30 +71,32 @@ pipeline { sh "docker-compose push" } } - stage ('Deploy') { + stage('Deploy') { environment { DOCKER_TLS_VERIFY = 1 } - 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}" - } + parallel { + stage('Host 1') { + environment { + DOCKER_HOST = "${env.DOCKER_HOST_1}" + } + steps { sh "docker-compose pull" sh "docker-compose up -d" } - ) + }, + stage('Host 2') { + environment { + DOCKER_HOST = "${env.DOCKER_HOST_2}" + } + steps { + sh "docker-compose pull" + sh "docker-compose up -d" + } + } } } - stage ('Cleanup') { + stage('Cleanup') { steps { sh 'docker logout $REGISTRY' } From 7a4510ebc86edcaebb19d568ab39b0624f95c7cc Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Fri, 11 Jan 2019 14:16:34 +0100 Subject: [PATCH 18/25] Jenkinsfile fixes --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 3ad377aa1..fc714f76b 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -84,7 +84,7 @@ pipeline { sh "docker-compose pull" sh "docker-compose up -d" } - }, + } stage('Host 2') { environment { DOCKER_HOST = "${env.DOCKER_HOST_2}" From ac41a77d2fe04f7e06a50132e8c5ecfcf1b8f973 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Fri, 11 Jan 2019 14:26:05 +0100 Subject: [PATCH 19/25] Jenkinsfile fixes --- Jenkinsfile | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index fc714f76b..09ef115b4 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -51,10 +51,12 @@ pipeline { environment { NODE_ENV = '' } - steps { - nodejs('node-lts') { - sh "npm install --no-audit" - sh "gulp install" + parallel { + stage('npm') { + steps { nodejs('node-lts') { sh "npm install --no-audit" } } + } + stage('Gulp') { + steps { nodejs('node-lts') { sh "gulp install" } } } } } @@ -74,6 +76,7 @@ pipeline { stage('Deploy') { environment { DOCKER_TLS_VERIFY = 1 + DOCKER_CERT_PATH = credentials('docker') } parallel { stage('Host 1') { From d7cacd62b3d05ea4988a6e23d97b5a6fce7d7cc8 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Fri, 11 Jan 2019 14:40:13 +0100 Subject: [PATCH 20/25] Jenkinsfile fix --- Jenkinsfile | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 09ef115b4..f99b891b6 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -51,12 +51,10 @@ pipeline { environment { NODE_ENV = '' } - parallel { - stage('npm') { - steps { nodejs('node-lts') { sh "npm install --no-audit" } } - } - stage('Gulp') { - steps { nodejs('node-lts') { sh "gulp install" } } + steps { + nodejs('node-lts') { + sh "npm install --no-audit" + sh "gulp install" } } } @@ -76,8 +74,8 @@ pipeline { stage('Deploy') { environment { DOCKER_TLS_VERIFY = 1 - DOCKER_CERT_PATH = credentials('docker') } + withCredentials([dockerCert(credentialsId: 'docker', variable: 'DOCKER_CERT_PATH')]) { parallel { stage('Host 1') { environment { @@ -85,7 +83,9 @@ pipeline { } steps { sh "docker-compose pull" - sh "docker-compose up -d" + withCredentials([dockerCert(credentialsId: 'docker', variable: 'DOCKER_CERT_PATH')]) { + sh "docker-compose up -d" + } } } stage('Host 2') { @@ -94,10 +94,13 @@ pipeline { } steps { sh "docker-compose pull" - sh "docker-compose up -d" + withCredentials([dockerCert(credentialsId: 'docker', variable: 'DOCKER_CERT_PATH')]) { + sh "docker-compose up -d" + } } } } + } } stage('Cleanup') { steps { From 2e0b5717ed957a6412ffe3c11790615e1d92a8ec Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Fri, 11 Jan 2019 14:42:40 +0100 Subject: [PATCH 21/25] Jenkinsfile fixes --- Jenkinsfile | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index f99b891b6..65326d4de 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -75,15 +75,14 @@ pipeline { environment { DOCKER_TLS_VERIFY = 1 } - withCredentials([dockerCert(credentialsId: 'docker', variable: 'DOCKER_CERT_PATH')]) { parallel { stage('Host 1') { environment { DOCKER_HOST = "${env.DOCKER_HOST_1}" } steps { - sh "docker-compose pull" withCredentials([dockerCert(credentialsId: 'docker', variable: 'DOCKER_CERT_PATH')]) { + sh "docker-compose pull" sh "docker-compose up -d" } } @@ -93,14 +92,13 @@ pipeline { DOCKER_HOST = "${env.DOCKER_HOST_2}" } steps { - sh "docker-compose pull" withCredentials([dockerCert(credentialsId: 'docker', variable: 'DOCKER_CERT_PATH')]) { + sh "docker-compose pull" sh "docker-compose up -d" } } } } - } } stage('Cleanup') { steps { From 133c32b4ea51a4458e5d5e08b7b13b11ee08efd7 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Fri, 11 Jan 2019 14:49:25 +0100 Subject: [PATCH 22/25] Jenkinsfile fixes --- Jenkinsfile | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 65326d4de..83d500e22 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -7,7 +7,7 @@ pipeline { environment { REGISTRY = 'registry.verdnatura.es' DOCKER_HOST_1 = 'tcp://vch1.verdnatura.es:2376' - DOCKER_HOST_2 = 'tcp://vch1.verdnatura.es:2376' + DOCKER_HOST_2 = 'tcp://vch2.verdnatura.es:2376' TAG = "${env.BRANCH_NAME}" } stages { @@ -47,23 +47,16 @@ pipeline { echo "Committer: ${env.GIT_COMMITTER_EMAIL}" } } - stage('Install') { - environment { - NODE_ENV = '' - } - steps { - nodejs('node-lts') { - sh "npm install --no-audit" - sh "gulp install" - } - } - } stage('Build') { environment { CREDS = credentials('docker-registry') } steps { nodejs('node-lts') { + withEnv(['NODE_ENV=']) { + sh "npm install --no-audit" + sh "gulp install" + } sh "gulp build" } sh 'docker login --username $CREDS_USR --password $CREDS_PSW $REGISTRY' From 1529f3348b1cff4c25514a8aafb007e5cf23bf77 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Fri, 11 Jan 2019 14:51:01 +0100 Subject: [PATCH 23/25] Jenkinsfile fixes --- Jenkinsfile | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 83d500e22..b1cdbb499 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,7 +1,5 @@ #!/usr/bin/env groovy -def buildError - pipeline { agent any environment { @@ -102,9 +100,7 @@ pipeline { post { always { script { - if (!env.GIT_COMMITTER_EMAIL) - return - + if (!env.GIT_COMMITTER_EMAIL) return mail( to: env.GIT_COMMITTER_EMAIL, subject: "Pipeline: ${env.JOB_NAME} (${env.BUILD_NUMBER}): ${currentBuild.result}", From 69f822df7022f27542d5a506ef2b0d74ba52790a Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Fri, 11 Jan 2019 15:31:14 +0100 Subject: [PATCH 24/25] Jenkinsfile fixes --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index b1cdbb499..126ff59e6 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -103,7 +103,7 @@ pipeline { if (!env.GIT_COMMITTER_EMAIL) return mail( to: env.GIT_COMMITTER_EMAIL, - subject: "Pipeline: ${env.JOB_NAME} (${env.BUILD_NUMBER}): ${currentBuild.result}", + subject: "Pipeline: ${env.JOB_NAME} (${env.BUILD_NUMBER}): ${currentBuild.currentResult}", body: "Check status at ${env.BUILD_URL}" ) } From aa74f8ce6aa715d3677b59102da36214eb32c3ae Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Fri, 11 Jan 2019 15:36:04 +0100 Subject: [PATCH 25/25] Jenkinsfile fixes --- Jenkinsfile | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 126ff59e6..f1cfe51ff 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -13,6 +13,10 @@ pipeline { steps { script { env.COMPOSE_PROJECT_NAME = env.JOB_NAME.replace('/', '-'); + env.GIT_COMMITTER_EMAIL = sh( + script: "git --no-pager show -s --format='%ae'", + returnStdout: true + ).trim() switch (env.BRANCH_NAME) { case 'master': @@ -34,14 +38,6 @@ pipeline { break; } } - - 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}" } }