-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
119 lines (109 loc) · 4.99 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
pipeline {
agent any
options {
disableConcurrentBuilds()
}
stages {
stage('Build') {
stages {
stage('build tfh-backend') {
steps {
script {
dir('tfh-backend') {
echo 'Building tfh-backend'
sh("mvn clean install -DskipTests")
}
}
}
}
stage('build tfh-frontend') {
steps {
script {
dir('tfh-frontend') {
echo 'Building tfh-frontend'
sh('npm i --force')
sh('npm run build')
}
}
}
}
stage('build docker') {
stages {
stage('build docker backend') {
steps {
script {
dir('tfh-backend') {
echo 'Building docker backend'
sh('docker build -t tfh-backend .')
}
}
}
}
stage('build docker frontend') {
steps {
script {
dir('tfh-frontend') {
echo 'Building docker frontend'
sh('docker build -t tfh-frontend .')
}
}
}
}
stage('connect to digital ocean') {
steps {
script {
sh('docker login -u $digitalOceanApiToken -p $digitalOceanApiToken registry.digitalocean.com')
}
}
}
stage('push to digitalocean') {
stages {
stage('push backend image') {
steps {
script {
sh('docker tag tfh-backend registry.digitalocean.com/tfh-container/tfh-backend')
sh('docker push registry.digitalocean.com/tfh-container/tfh-backend')
}
}
}
stage('push frontend image') {
steps {
script {
sh('docker tag tfh-frontend registry.digitalocean.com/tfh-container/tfh-frontend')
sh('docker push registry.digitalocean.com/tfh-container/tfh-frontend')
}
}
}
}
}
}
}
}
}
stage('Deploy') {
stages {
stage('deploy apps') {
steps {
script {
sh('docker stop tfh-backend || true')
sh('docker stop tfh-frontend || true')
sh('docker rm tfh-backend || true')
sh('docker rm tfh-frontend || true')
sh('docker image rm registry.digitalocean.com/tfh-container/tfh-backend')
sh('docker image rm registry.digitalocean.com/tfh-container/tfh-frontend')
sh('docker pull registry.digitalocean.com/tfh-container/tfh-backend')
sh('docker pull registry.digitalocean.com/tfh-container/tfh-frontend')
sh('docker run -e DATABASE_HOST=$DATABASE_HOST -e DATABASE_PORT=$DATABASE_PORT -e DATABASE_NAME=$DATABASE_NAME -e DATABASE_USER=$DATABASE_USER -e DATABASE_PASSWORD=$DATABASE_PASSWORD -e JWT_SECRET=$JWT_SECRET -p 8081:8081 --name tfh-backend -d registry.digitalocean.com/tfh-container/tfh-backend')
sh('docker run -p 80:80 --name tfh-frontend -d registry.digitalocean.com/tfh-container/tfh-frontend')
}
}
}
}
}
}
post {
failure {
emailext body: 'The last build has failed. Please check the logs and fix the issues.', subject: 'Jenkins - Build failure', to: 'ianicumanschii@gmail.com'
}
}
}