forked from dockersamples/example-voting-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
108 lines (101 loc) · 3.63 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
def COLOR_MAP = [
'SUCCESS': 'good',
'FAILURE': 'danger',
]
pipeline {
agent any
environment {
SONARSERVER = 'sserver'
SONARSCANNER = 'sonar'
registryv = "mohammadayan/vote"
registryw = "mohammadayan/worker"
registryr = "mohammadayan/result"
registrys = "mohammadayan/seeddata"
registryCredential = 'dockerhub'
}
stages {
stage('Initial Setup') {
steps {
script {
scannerHome = tool "${SONARSCANNER}"
}
}
}
stage('Sonar Analysis and Quality Gates') {
steps {
script {
withSonarQubeEnv("${SONARSERVER}") {
sh """
"${scannerHome}"/bin/sonar-scanner \
-Dsonar.projectKey=Voting-App \
-Dsonar.sources=. \
-Dsonar.host.url=http://13.233.111.148:9000 \
-Dsonar.token=sqp_96442758c0a6472f6faf110ddb7a210abc9b406d
"""
}
timeout(time: 10, unit: 'MINUTES') {
waitForQualityGate abortPipeline: true
}
}
}
}
stage('Building Docker Images'){
steps{
script{
dockerImage1 = docker.build registryv + ":$BUILD_NUMBER", "./vote"
dockerImage2 = docker.build registryw + ":$BUILD_NUMBER", "./worker"
dockerImage3 = docker.build registryr + ":$BUILD_NUMBER", "./result"
dockerImage4 = docker.build registrys + ":$BUILD_NUMBER", "./seed-data"
}
}
}
stage('Pushing Images to DockerHub'){
steps{
script{
docker.withRegistry( '', registryCredential ) {
dockerImage1.push("$BUILD_NUMBER")
dockerImage1.push('latest')
}
docker.withRegistry( '', registryCredential ) {
dockerImage2.push("$BUILD_NUMBER")
dockerImage2.push('latest')
}
docker.withRegistry( '', registryCredential ) {
dockerImage3.push("$BUILD_NUMBER")
dockerImage3.push('latest')
}
docker.withRegistry( '', registryCredential ) {
dockerImage4.push("$BUILD_NUMBER")
dockerImage4.push('latest')
}
}
}
}
stage('Removing Build DockerImages From Jenkins'){
steps{
script{
sh 'docker rmi -f $(docker images -q)'
}
}
}
stage('Deploying Images to EKS cluster'){
agent { label 'eks-controller'}
steps{
script{
sh 'kubectl delete all --all'
sh 'rm -rf /home/ubuntu/project'
sh 'git clone https://github.com/MuhmmadAyan/example-voting-app.git /home/ubuntu/project'
sh 'kubectl create -f /home/ubuntu/project/k8s-specifications/kubernetes/'
}
}
}
}
post {
always {
echo 'Slack Notifications.'
slackSend channel: '#general',
color: COLOR_MAP[currentBuild.currentResult],
message: "*${currentBuild.currentResult}:* Job ${env.JOB_NAME} build ${env.BUILD_NUMBER} \n More info at: ${env.BUILD_URL}" // plugin feature of slack
}
}
}