-
Notifications
You must be signed in to change notification settings - Fork 4
/
JenkinsFile
113 lines (104 loc) · 3.6 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
pipeline {
agent any
environment {
frontendImage='rushikesh0203/virtuallab_frontend'
backendImage='rushikesh0203/virtuallab_backend'
dbImage='rushikesh0203/virtuallab_db'
mongodbImage='rushikesh0203/virtuallab_mongodb'
dockerfrontendImage = ''
dockerbackendImage = ''
dockerdbImage = ''
dockermongodbImage=''
}
stages {
stage('Git Checkout') {
steps {
script{
git 'https://github.com/vinayakchaturvedi/VirtualLab'
}
}
}
stage('Unit Test') {
steps {
script{
sh 'mvn clean test '
}
}
}
stage('Build executable jar') {
steps {
script{
sh 'mvn -Dmaven.test.skip=true package'
}
}
}
stage('Build npm modules') {
steps {
script{
sh 'npm clean-install --prefix ./src/main/webapp/virtual-lab-ui'
}
}
}
stage('Building Backend Image') {
steps{
script {
dockerbackendImage = docker.build "$backendImage"
}
}
}
stage('Building Frontend Image') {
steps{
script {
dockerfrontendImage = docker.build ("$frontendImage","-f src/main/webapp/virtual-lab-ui/Dockerfile .")
}
}
}
stage('Building DB Images') {
steps{
script {
dockerdbImage = docker.build ("$dbImage","-f dbDocker/MySQL/Dockerfile .")
dockermongodbImage = docker.build ("$mongodbImage","-f dbDocker/MongoDb/Dockerfile .")
}
}
}
stage('Deploy Image') {
steps{
script {
docker.withRegistry( '', 'Docker' ) {
dockerfrontendImage.push("${env.BUILD_NUMBER}")
dockerfrontendImage.push("latest")
dockerbackendImage.push("${env.BUILD_NUMBER}")
dockerbackendImage.push("latest")
dockerdbImage.push("${env.BUILD_NUMBER}")
dockerdbImage.push("latest")
dockermongodbImage.push("${env.BUILD_NUMBER}")
dockermongodbImage.push("latest")
}
}
}
}
stage('Remove Unused docker image') {
steps{
script{
sh "docker rmi $frontendImage:latest;docker rmi $frontendImage:${env.BUILD_NUMBER}";
sh "docker rmi $backendImage:latest;docker rmi $backendImage:${env.BUILD_NUMBER}";
sh "docker rmi $dbImage:latest;docker rmi $dbImage:${env.BUILD_NUMBER}";
sh "docker rmi $mongodbImage:latest;docker rmi $mongodbImage:${env.BUILD_NUMBER}";
}
}
}
stage('Start the Deployment to Production Server'){
steps{
sh " ansible-playbook ./DeployScripts/ServiceUp.yml ";
}
}
}
post {
failure {
mail bcc: '', body: 'New Build failed', cc: 'vinayak.chaturvedi96@gmail.com swapnil.jain96@gmail.com', from: '', replyTo: '', subject: 'Deployment Status', to: 'rushikesh0203@gmail.com'
}
success {
mail bcc: '', body: 'New version is Up and Running', cc: 'vinayak.chaturvedi96@gmail.com swapnil.jain96@gmail.com', from: '', replyTo: '', subject: 'Deployment Status', to: 'rushikesh0203@gmail.com'
}
}
}