salix/Jenkinsfile

69 lines
1.9 KiB
Plaintext
Raw Normal View History

2017-05-12 10:41:35 +00:00
#!/usr/bin/env groovy
2019-01-08 13:01:04 +00:00
try {
2019-01-08 14:54:02 +00:00
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-08 13:01:04 +00:00
node {
stage ('Checkout') {
checkout scm
2019-01-08 15:27:47 +00:00
env.GIT_COMMIT_EMAIL = sh (
script: "git --no-pager show -s --format='%ae'",
returnStdout: true
).trim()
echo "Commiter: ${env.GIT_COMMIT_EMAIL}"
2018-10-24 12:10:41 +00:00
}
2019-01-08 15:07:21 +00:00
stage ('Build') {
2019-01-08 13:01:04 +00:00
nodejs('node-lts') {
2019-01-08 14:54:02 +00:00
sh "env NODE_ENV= npm install --no-audit"
2019-01-08 13:01:04 +00:00
sh "gulp install"
sh "gulp build"
2019-01-02 00:16:28 +00:00
}
2019-01-08 13:01:04 +00:00
}
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;
}
2019-01-02 01:02:29 +00:00
2019-01-07 08:54:00 +00:00
2019-01-08 13:01:04 +00:00
env.COMPOSE_PROJECT_NAME = env.JOB_NAME.replace('/', '-');
env.DOCKER_TLS_VERIFY = 1
env.TAG = env.BRANCH_NAME
2019-01-08 12:14:18 +00:00
2019-01-08 13:01:04 +00:00
env.DOCKER_HOST = 'tcp://vch1.verdnatura.es:2376';
sh "docker-compose up --build -d"
2019-01-02 01:02:29 +00:00
2019-01-08 13:01:04 +00:00
env.DOCKER_HOST = 'tcp://vch2.verdnatura.es:2376';
sh "docker-compose up --build -d"
}
2019-01-01 22:43:00 +00:00
}
2018-10-24 12:41:38 +00:00
}
2019-01-08 13:01:04 +00:00
2019-01-08 15:00:25 +00:00
mail(
2019-01-08 15:27:47 +00:00
to: env.GIT_COMMIT_EMAIL,
2019-01-08 15:00:25 +00:00
subject: "Pipeline success: ${env.JOB_NAME} (${env.BUILD_NUMBER})",
body: "Check status at ${env.BUILD_URL}"
)
2019-01-08 13:01:04 +00:00
} catch(e) {
2019-01-08 15:00:25 +00:00
mail(
2019-01-08 15:27:47 +00:00
to: env.GIT_COMMIT_EMAIL,
2019-01-08 15:00:25 +00:00
subject: "Pipeline failed: ${env.JOB_NAME} (${env.BUILD_NUMBER})",
body: "Check status at ${env.BUILD_URL}"
)
2019-01-07 08:54:00 +00:00
}