salix/Jenkinsfile

100 lines
2.7 KiB
Plaintext
Raw Normal View History

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-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') {
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-08 16:26:09 +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') {
2019-01-11 07:28:55 +00:00
env.COMPOSE_PROJECT_NAME = env.JOB_NAME.replace('/', '-');
env.TAG = env.BRANCH_NAME
2019-01-02 01:02:29 +00:00
2019-01-11 07:28:55 +00:00
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"
withCredentials([dockerCert(
credentialsId: 'docker',
variable: 'DOCKER_CERT_PATH')
]) {
env.DOCKER_TLS_VERIFY = 1
2019-01-08 12:14:18 +00:00
env.DOCKER_HOST = 'tcp://vch1.verdnatura.es:2376';
sh "docker-compose pull"
sh "docker-compose up -d"
2019-01-02 01:02:29 +00:00
env.DOCKER_HOST = 'tcp://vch2.verdnatura.es:2376';
sh "docker-compose pull"
sh "docker-compose up -d"
}
2019-01-11 07:58:51 +00:00
sh "docker logout ${env.REGISTRY}"
2019-01-08 13:01:04 +00:00
}
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;