-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
101 lines (86 loc) · 2.46 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
pipeline {
agent any
tools {
jdk 'jdk17'
maven 'maven3'
}
environment{
SCANNER_HOME= tool 'sonar-scanner'
}
stages{
stage('Git-checkout'){
steps{
git branch: 'main', credentialsId: 'git-cred',
url: 'https://github.com/vank1999/petclinic-java.git'
}
}
stage('code-compile'){
steps{
sh "mvn clean compile"
}
}
stage('unit-tests'){
steps{
sh "mvn test"
}
}
stage('Trivy scan') {
steps {
sh 'trivy fs --format table -o trivy-fs-report.html .'
}
}
stage('sonarqube-analysis'){
steps{
withSonarQubeEnv('sonar') {
sh ''' $SCANNER_HOME/bin/sonar-scanner -Dsonar.projectName=Petclinic \
-Dsonar.java.binaries=. \
-Dsonar.projectKey=Petclinic '''
}
}
}
stage('OWASP scan') {
steps {
dependencyCheck additionalArguments: '', odcInstallation: 'DP-check'
dependencyCheckPublisher pattern: '**/dependency-check-report.xml'
}
}
stage('Code-Build') {
steps {
sh "mvn clean install"
}
}
stage('Docker Build') {
steps {
script{
withDockerRegistry(credentialsId: 'docker-cred', toolName: 'docker') {
sh "docker build -t vank1999/petclinic:latest . "
}
}
}
}
stage('Trivy Scan Image') {
steps {
sh "trivy image --format table -o trivy-image-report.html vank1999/petclinic:latest"
}
}
stage('Docker Push') {
steps {
script{
withDockerRegistry(credentialsId: 'docker-cred', toolName: 'docker') {
sh "docker push vank1999/petclinic:latest "
}
}
}
}
stage('Deploy using docker') {
steps {
sh "docker run -d --name petclinic -p 8082:8082 vank1999/petclinic:latest"
}
}
stage('Deploy to Tomcat') {
steps {
sh " sudo cp /var/lib/jenkins/workspace/petclinic/target/petclinic.war /opt/tomcat/webapps/ "
}
}
}
}