#!/usr/bin/env groovy 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; } node { stage ('Checkout') { checkout scm echo env.GIT_COMMITTER_NAME echo env.GIT_AUTHOR_NAME echo env.GIT_USER echo env.CHANGE_AUTHOR echo env.CHANGE_AUTHOR_DISPLAY_NAME echo env.CHANGE_AUTHOR_EMAIL } stage ('Build') { nodejs('node-lts') { sh "env NODE_ENV= npm install --no-audit" sh "gulp install" sh "gulp build" } } 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.DOCKER_TLS_VERIFY = 1 env.TAG = env.BRANCH_NAME 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" } } } mail( to: 'juan@verdnatura.es', subject: "Pipeline success: ${env.JOB_NAME} (${env.BUILD_NUMBER})", body: "Check status at ${env.BUILD_URL}" ) } catch(e) { mail( to: 'juan@verdnatura.es', subject: "Pipeline failed: ${env.JOB_NAME} (${env.BUILD_NUMBER})", body: "Check status at ${env.BUILD_URL}" ) }