-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathjenkinsfile
More file actions
108 lines (90 loc) · 3.21 KB
/
jenkinsfile
File metadata and controls
108 lines (90 loc) · 3.21 KB
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
pipeline{
agent any;
tools{
maven 'maven'
jdk 'JDK11'
}
stages{
stage('Fetch project from github'){
steps{
git branch: 'master', url: 'https://github.com/sujjadshaik/todo-app.git'
}
}
stage('Maven package'){
steps{
sh 'mvn -f app/pom.xml package'
}
}
stage('sonar analysis'){
steps{
withSonarQubeEnv('sonarQube'){
sh 'mvn -f app/pom.xml sonar:sonar'
}
}
}
stage('deploy to artifactor'){
steps{
rtUpload (
serverId: 'ARTIFACTORY-SERVER',
spec: '''{
"files": [
{
"pattern": "app/target/*.war",
"target": "art-doc-dev-loc/todo-app/"
}
]
}''',
)
}
}
stage('download artifact'){
steps{
rtDownload (
serverId: "ARTIFACTORY-SERVER",
spec:"""{
"files": [
{
"pattern": "art-doc-dev-loc/todo-app/**",
"target": "app/artifacts/"
}
]
}"""
)
}
}
stage('Docker build'){
steps{
sh 'docker image prune -a --force'
sh 'docker-compose build'
}
}
stage('Pushing images to docker hub'){
steps{
withCredentials([string(credentialsId: 'docker-pwd', variable: 'dockerHubPWD')]) {
// some block
sh "docker login -u sujjad -p ${dockerHubPWD}"
}
sh "docker commit todo-app sujjad/todo-app:v${env.BUILD_ID}"
sh "docker push sujjad/todo-app:v${env.BUILD_ID}"
}
}
stage('deploying it to kubernetes'){
steps{
sh 'chmod +x change-tag.sh'
sh """./change-tag.sh v${env.BUILD_ID}"""
sh 'cat k8s/api-deployment.yaml'
withKubeConfig(caCertificate: '', clusterName: '', contextName: '', credentialsId: 'kube-gcp', namespace: '', serverUrl: 'https://35.222.102.119') {
// some block
sh 'kubectl apply -f k8s/database-deployment.yaml'
}
sleep(120)
withKubeConfig(caCertificate: '', clusterName: '', contextName: '', credentialsId: 'kube-gcp', namespace: '', serverUrl: 'https://35.222.102.119') {
// some block
sh 'kubectl apply -f k8s/api-deployment.yaml'
sh 'kubectl get pods'
sh 'kubectl get svc'
}
}
}
}
}