forked from jaiswaladi246/Ekart
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJenkinsfile
97 lines (84 loc) · 2.77 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
pipeline {
agent any
tools {
maven 'maven3'
jdk 'jdk17'
}
environment {
SCANNER_HOME = tool 'sonar-scanner'
}
stages {
stage('Checkout') {
steps {
git branch: 'main', url: 'https://github.com/adityadhopade/Ekart.git'
}
}
stage('Compile Code') {
steps {
sh "mvn compile"
}
}
stage('Unit Test') {
steps {
sh "mvn test -DskipTests=true"
}
}
stage('sonar analysis') {
steps {
withSonarQubeEnv('sonar') {
sh ''' $SCANNER_HOME/bin/sonar-scanner -D sonar.projectKey=EKART -D sonar.projectName=EKART \
-D sonar.java.binaries=. '''
}
}
}
stage('OWASP Dependency Check') {
steps {
dependencyCheck additionalArguments: '', odcInstallation: 'DC'
dependencyCheckPublisher pattern: '**/dependency-check-report.xml'
}
}
stage('Build Application') {
steps {
sh "mvn package -DskipTests=true"
}
}
stage('Deploy to Nexus') {
steps {
withMaven(globalMavenSettingsConfig: 'global-maven', jdk: 'jdk17', maven: 'maven3', mavenSettingsConfig: '', traceability: true) {
sh "mvn deploy -DskipTests=true"
}
}
}
stage('Docker Build and Tag') {
steps {
script {
withDockerRegistry(credentialsId: 'dockerhub-credentials') {
sh "docker build -t adityadho/ekart:latest -f docker/Dockerfile ."
}
}
}
}
stage('Trivy Scanning') {
steps {
sh "trivy image adityadho/ekart:latest > trivy_report.txt"
}
}
stage('PUSH Image to DTR') {
steps {
script {
withDockerRegistry(credentialsId: 'dockerhub-credentials') {
sh "docker push adityadho/ekart:latest"
}
}
}
}
stage('Deploy to Kubernetes') {
steps {
withKubeConfig(caCertificate: '', clusterName: '', contextName: '', credentialsId: 'k8-token', namespace: 'webapps', restrictKubeConfigAccess: false, serverUrl: 'https://172.31.89.0:6443') {
sh "kubectl apply -f deploymentservice.yml -n webapps"
sh "kubectl get svc -n webapps"
}
}
}
}
}