-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathJenkinsfile
75 lines (62 loc) · 2.45 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
pipeline {
agent any
tools{
maven '3.8.6'
nodejs '16.10.0'
}
environment{
dockercredentials=credentials('dockerhubid')
}
stages {
stage('Build & Package spring app') {
steps {
dir('springboot-backend') {
sh 'mvn clean '
sh 'mvn install -DskipTests '
}
}
}
stage('Build images of both app') {
steps {
dir('springboot-backend') {
sh 'docker build -t springboot-backend:$BUILD_NUMBER . '
}
dir('react-frontend') {
sh 'docker build -t react-frontend:$BUILD_NUMBER . '
}
}
}
stage('Push images to hub') {
steps {
sh 'echo $dockercredentials_PSW | docker login -u $dockercredentials_USR --password-stdin '
sh 'docker image tag springboot-backend:$BUILD_NUMBER lugar2020/springboot-backend:$BUILD_NUMBER'
sh 'docker image push lugar2020/springboot-backend:$BUILD_NUMBER'
sh 'docker image tag react-frontend:$BUILD_NUMBER lugar2020/react-frontend:$BUILD_NUMBER'
sh 'docker image push lugar2020/react-frontend:$BUILD_NUMBER'
}
}
stage('deploy on kubernetes') {
steps {
dir('kubernetes'){
sh ''' final_tag=$(echo $BUILD_NUMBER | tr -d ' ')
sed -i "s/docker_tag/$final_tag/g" backend.yml
'''
sh ''' final_tag=$(echo $BUILD_NUMBER | tr -d ' ')
sed -i "s/docker_tag/$final_tag/g" frontend.yml
'''
}
dir('ansible') {
ansiblePlaybook become: true, credentialsId: 'masternodeid', installation: 'ansible', inventory: 'hosts.ini', playbook: 'deploy-playbook.yml'
}
}
}
stage('Clean up') {
steps {
sh 'docker rmi lugar2020/springboot-backend:$BUILD_NUMBER --force'
sh 'docker rmi springboot-backend:$BUILD_NUMBER --force'
sh 'docker rmi lugar2020/react-frontend:$BUILD_NUMBER --force'
sh 'docker rmi react-frontend:$BUILD_NUMBER --force'
}
}
}
}