-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjenkins
More file actions
110 lines (91 loc) · 3.16 KB
/
jenkins
File metadata and controls
110 lines (91 loc) · 3.16 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
109
110
pipeline {
agent any
tools {
jdk 'jdk17'
maven 'maven3'
}
environment {
SCANNER_HOME= tool 'sonar-scanner'
}
stages {
stage('git checkout') {
steps {
git branch: 'main', url: 'https://github.com/ramasamy361/Full-stack-Blogging-App.git'
}
}
stage('compile') {
steps {
sh "mvn compile"
}
}
stage('Test') {
steps {
sh "mvn test"
}
}
stage('trivy FS Scan') {
steps {
sh "trivy fs --format table -o fs.html ."
}
}
stage('SonarQube Analysis') {
steps {
withSonarQubeEnv('sonar-server') {
sh '''$SCANNER_HOME/bin/sonar-scanner -Dsonar.projectName-Blogging-app -Dsonar.projectKey=Blogging-app \
-Dsonar.java.binaries=target '''
}
}
}
stage('Build') {
steps {
sh "mvn package"
}
}
stage('Public Artifacts') {
steps {
withMaven(globalMavenSettingsConfig: 'maven-settings', jdk: 'jdk17', maven: 'maven3', mavenSettingsConfig: '', traceability: true) {
sh "mvn deploy"
}
}
}
stage('Docker Build & Tag') {
steps {
script {
withDockerRegistry(credentialsId: 'docker-cred', toolName: 'docker') {
sh "docker build -t ram1844/bloggingapp:latest ."
}
}
}
}
stage('trivy image Scan') {
steps {
sh "trivy image --format table -o image.html ram1844/bloggingapp:latest"
}
}
stage('docker push Image') {
steps {
script {
withDockerRegistry(credentialsId: 'docker-cred', toolName: 'docker') {
sh "docker push ram1844/bloggingapp:latest"
}
}
}
}
stage('K8-Deploy') {
steps {
withKubeConfig(caCertificate: '', clusterName: ' devopsshack-cluster', contextName: '', credentialsId: 'k8-cred', namespace: 'webapps', restrictKubeConfigAccess: false, serverUrl: 'https://C83E020C826B54CECCD49F15641418BE.gr7.us-east-1.eks.amazonaws.com') {
sh 'kubectl apply -f deployment-service.yml'
sleep 20
}
}
}
stage('verify the Deployment') {
steps {
withKubeConfig(caCertificate: '', clusterName: ' devopsshack-cluster', contextName: '', credentialsId: 'k8-cred', namespace: 'webapps', restrictKubeConfigAccess: false, serverUrl: 'https://C83E020C826B54CECCD49F15641418BE.gr7.us-east-1.eks.amazonaws.com') {
sh 'kubectl get pods'
sh 'kubectl get svc'
}
}
}
}
}