-
Notifications
You must be signed in to change notification settings - Fork 0
/
jenkins
89 lines (79 loc) · 2.77 KB
/
jenkins
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
pipeline {
agent any
environment {
SCANNER_HOME = tool 'sonarqube'
}
stages {
stage('Github Checkout') {
steps {
// Checkout the source code from the repository
checkout([$class: 'GitSCM',
branches: [[name: '*/main']],
userRemoteConfigs: [[url: 'https://github.com/tusuii/IAC_CICD_deployment.git']]])
}
}
stage('SonarQube Scan') {
steps {
script {
sh "${SCANNER_HOME}/bin/sonar-scanner \
-Dsonar.projectKey=sonarqube \
-Dsonar.projectName=sonarqube \
-Dsonar.sources=. \
-Dsonar.java.binaries=. \
-Dsonar.host.url=http://<sonarquve IP>/ \
-Dsonar.login=<login credientials from sonarqube generate them>"
}
}
}
stage('OWASP Scan') {
steps {
script {
// Perform OWASP Dependency Check
dependencyCheck additionalArguments: '''
-o './'
-s './'
-f 'ALL'
--prettyPrint''', odcInstallation: 'DP'
// Publish OWASP Dependency Check results
dependencyCheckPublisher pattern: 'dependency-check-report.xml'
}
}
}
stage('Build Docker Image') {
steps {
script {
// Check if Docker image exists
def imageExists = sh(script: "docker images -q webapp:latest", returnStatus: true) == 0
if (!imageExists) {
// Build Docker image if it doesn't exist
sh "docker build -t webapp ."
} else {
// Stop and remove existing Docker container
sh "docker stop app"
sh "docker rm app"
sh "docker build -t webapp ."
}
}
}
}
stage('Run Docker Application Container') {
steps {
// Run Docker container
script {
sh "docker run -d -p 8070:80 --name app webapp"
}
}
}
}
post {
success {
echo 'Docker container is up and running.'
}
failure {
echo 'Failed to build Docker image or run container.'
}
}
triggers {
githubPush()
}
}