-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfile
50 lines (48 loc) · 1.29 KB
/
Jenkinsfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
pipeline {
agent any
environment {
APP = "svelte-sample"
BUILD = "${JOB_NAME.replace('/', '-').replace(' ', '-').toLowerCase()}-${BUILD_NUMBER}"
EMAIL = sh(script: "git show -s --format='%ae' HEAD", returnStdout: true)
GIT_LAST_CHANGE = sh(script: 'git show', returnStdout: true)
EMAIL_BODY = "Project: ${JOB_NAME}\nBuild Number: ${BUILD_NUMBER}\n\nLast change:\n\n${env.GIT_LAST_CHANGE}"
COMPOSE = "docker-compose -f docker-compose.yml -p $APP"
VERSION = sh(script: 'git describe --tags --always --long', returnStdout: true).trim()
RUN_TESTS = "docker run --network ${APP}_default -e BUILD=$BUILD"
}
stages {
stage('Build UI') {
steps {
sh "docker build --target build-ui -t ${BUILD}_ui ."
}
}
stage('Test UI') {
steps {
sh "docker run -t ${BUILD}_ui npm run test"
}
}
stage('Build final') {
when {
branch 'master'
}
steps {
sh "$COMPOSE build --build-arg VERSION=$VERSION"
}
}
stage('Deploy') {
when {
branch 'master'
}
steps {
sh "$COMPOSE up -d --remove-orphans"
}
}
}
post {
failure {
script {
if (EMAIL) mail to: EMAIL, subject: "$APP ($BRANCH_NAME) build failed", body: EMAIL_BODY
}
}
}
}