-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathJenkinsfile
100 lines (93 loc) · 3.51 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
pipeline {
agent any
stages {
stage("Compiling Application") {
agent {
docker {
image 'maven'
reuseNode true
}
}
steps {
sh 'mvn clean install'
}
}
stage("Unit & Integration Testing") {
agent {
docker {
image 'maven'
reuseNode true
}
}
steps {
sh 'mvn test'
sh 'mvn verify -DskipUnitTests'
}
post {
failure {
slackSend(channel: "#general", color: '#D70040', message: "Build failed in stage ${env.STAGE_NAME}")
}
}
}
stage("Static Code Analysis(SonarQube)") {
agent {
docker {
image 'maven'
reuseNode true
}
}
steps {
withSonarQubeEnv(installationName: 'sonar-api') {
sh 'mvn clean package sonar:sonar'
}
}
post {
failure {
slackSend(channel: "#general", color: '#D70040', message: "Build failed in stage ${env.STAGE_NAME}")
}
}
}
stage("Build Docker Image") {
steps {
echo 'Building Docker Image'
sh "docker build -t saurabhkr952/counter-demo-app:$BUILD_NUMBER ."
}
}
stage("Pushing Artifact to Dockerhub") {
steps {
echo 'deploying the application...'
withCredentials([usernamePassword(credentialsId: 'docker-hub-repo', passwordVariable: 'PASS', usernameVariable: 'USER')]) {
sh "echo $PASS | docker login -u $USER --password-stdin"
sh "docker push saurabhkr952/counter-demo-app:$BUILD_NUMBER"
}
}
}
stage("checkout mainfest repo (Helm Chart)") {
steps {
git credentialsId: 'github-credentials',
url: 'https://github.com/Saurabhkr952/counter-demo-app-manifest-Helm.git',
branch: 'main'
}
}
stage("Update k8s manifest Repo") {
steps {
echo "pushing updated manifest to repository"
withCredentials([usernamePassword(credentialsId: 'github-credentials', passwordVariable: 'password', usernameVariable: 'username')]) {
sh " sed -i 's+saurabhkr952/counter-demo-app:.*+saurabhkr952/counter-demo-app:$BUILD_NUMBER+g' templates/demo-counter-app.yaml"
sh "git add -A"
sh "git commit -m 'Updated image tag | Image Version=$BUILD_NUMBER'"
sh "git remote -v"
sh "git push https://[email protected]/Saurabhkr952/counter-demo-app-manifest-Helm.git HEAD:main"
}
}
}
}
post {
success {
slackSend channel: "#general", color: '#0096FF', message: "Build Status: ${currentBuild.currentResult} \n${env.JOB_NAME} ${env.BUILD_NUMBER} \nMore info at: ${env.BUILD_URL}"
}
failure {
slackSend channel: "#general", color: '#D70040', message: "Build Status: ${currentBuild.currentResult} \n${env.JOB_NAME} ${env.BUILD_NUMBER} \nMore info at: ${env.BUILD_URL}"
}
}
}