-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJenkinsfile
119 lines (113 loc) · 3.52 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 {
timestamps()
}
environment {
SCANNER_HOME=tool 'sonar-scanner'
DOCKERHUB_CREDENTIALS=credentials('dockerhub')
DOCKERHUB_USERNAME='nishthapaul'
}
stages {
stage ("Clone Git") {
steps {
git branch: 'main', url: 'https://github.com/nisharathod231/Kalopsia.git'
}
}
stage ("Compile via Maven") {
steps {
dir('Backend') {
sh 'mvn clean compile'
}
}
}
stage ("Unit Tests via Maven") {
steps {
dir('Backend') {
sh 'mvn test'
}
}
}
stage ("Check Code Coverage") {
steps {
dir('Backend') {
sh 'mvn verify'
}
}
}
stage ("SonarQube Analysis") {
steps {
script {
try {
dir('Backend') {
withSonarQubeEnv('sonar-kalopsia') {
sh ''' $SCANNER_HOME/bin/sonar-scanner \
-Dsonar.projectName=KalopsiaBackend \
-Dsonar.java.binaries=. \
-Dsonar.sources=src/main/java \
-Dsonar.sourceEncoding=UTF-8 \
-Dsonar.language=java \
-Dsonar.projectKey=KalopsiaBackend '''
}
}
} catch (err) {
echo err.getMessage()
}
}
}
}
stage ("Build via Maven") {
steps {
dir('Backend') {
sh 'mvn install'
}
}
}
stage ("Create Docker Image of Backend") {
steps {
dir('Backend') {
sh 'docker build -t nishthapaul/kalopsia-backend -f Dockerfile.dev .'
}
}
}
stage ("Compile via NPM") {
steps {
dir('FrontEnd') {
sh 'npm install'
}
}
}
stage ("Create Docker Image of Frontend") {
steps {
dir('FrontEnd') {
sh 'docker build -t nishthapaul/kalopsia-frontend -f Dockerfile.dev .'
}
}
}
stage ("Push Docker Image") {
steps {
script {
sh 'docker login -u $DOCKERHUB_USERNAME -p $DOCKERHUB_CREDENTIALS'
sh 'docker push nishthapaul/kalopsia-backend'
sh 'docker push nishthapaul/kalopsia-frontend'
}
}
}
stage ("Run Ansible Playbook") {
steps {
sh 'ansible-playbook -i inventory.ini playbook.yml'
}
}
}
post {
success {
jacoco()
}
failure {
script {
def jenkinsBuildUrl = "http://localhost:8080/job/${env.JOB_NAME}/${env.BUILD_NUMBER}/console"
mail bcc: '', cc: '', from: '', replyTo: '', to: '[email protected]', subject: "Pipeline failed in Jenkins: ${env.JOB_NAME} - #${env.BUILD_NUMBER}", body: "Check console output at ${jenkinsBuildUrl} to view the results."
}
}
}
}