This repository has been archived by the owner on Jun 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
87 lines (87 loc) · 3.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
pipeline {
agent any
tools {nodejs "NodeJS"}
environment {
SEMGREP_APP_TOKEN = credentials('SEMGREP_APP_TOKEN')
}
stages {
stage('Test Docker') {
steps {
sh '''
docker version
'''
}
}
stage('Semgrep Scan') {
steps {
echo 'SAST Scanning'
sh 'semgrep scan'
}
}
stage('Setting up container') {
steps{
echo 'Setting up Container'
sh '''
rm -rf backend/database
rm -rf backend/api/migrations
docker compose -f jenkins-compose.yml up --build -d
'''
}
}
stage('Check OWASP') {
steps {
echo 'Check OWASP Stage'
// Add your OWASP Dependency-Check configuration here if needed
dependencyCheck additionalArguments: '''
-o './'
-s './'
-f 'ALL'
--prettyPrint''', odcInstallation: 'OWASP Dependency-Check Vulnerabilities'
dependencyCheckPublisher pattern: 'dependency-check-report.xml'
}
}
stage('Testing Stage') {
steps {
script {
// Containers are running, check their status
def frontendContainer = sh(script: 'docker inspect -f "{{.State.Status}}" nextjs_frontend', returnStdout: true).trim()
def backendContainer = sh(script: 'docker inspect -f "{{.State.Status}}" django_backend', returnStdout: true).trim()
def dbContainer = sh(script: 'docker inspect -f "{{.State.Status}}" backend_database', returnStdout: true).trim()
// Check if any container's status is not "Up"
if (frontendContainer != 'running' || backendContainer != 'running' || dbContainer != 'running') {
// At least one container is running but not "Up," send an email
emailext subject: "Docker Container Status Issue",
body: "One or more Docker containers are not in an 'Up' state. Please investigate. Check console output at '$BUILD_URL' to view the results.",
to: '2100755@sit.singaporetech.edu.sg'
} else {
// Run backend test case if the dockers are all up
sh '''
docker exec django_backend python manage.py makemigrations api
docker exec django_backend python manage.py migrate --fake-initial
docker exec django_backend python manage.py test --no-input
'''
emailext subject: "Tests Completed",
body: "Tests have been completed. Check console output at '$BUILD_URL' to view the results.",
to: '2100755@sit.singaporetech.edu.sg'
}
}
}
}
}
post {
always {
script {
sh '''
docker compose -f jenkins-compose.yml down
docker container prune -f
'''
}
}
// If the build has failed, send an email to notify
failure {
script {
emailext body: '$DEFAULT_CONTENT', subject: '$DEFAULT_SUBJECT', to: '2100755@sit.singaporetech.edu.sg'
}
}
}
}