-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
111 lines (107 loc) · 3.4 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
102
103
104
105
106
107
108
109
110
111
pipeline {
agent any
tools {
jdk 'jdk17'
nodejs 'node16'
}
environment {
SCANNER_HOME = tool 'sonar-scanner'
}
stages {
stage('Clean Workspace') {
steps {
cleanWs()
}
}
stage('Checkout from Git') {
steps {
git branch: 'main', url: 'https://github.com/TanishkaMarrott/Reddit-Clone-App.git'
}
}
stage("SonarQube Analysis") {
steps {
withSonarQubeEnv('sonar-server') {
sh '''$SCANNER_HOME/bin/sonar-scanner -Dsonar.projectName=Reddit \
-Dsonar.projectKey=Reddit'''
}
}
}
stage("Sonar Quality Gate") {
steps {
script {
waitForQualityGate abortPipeline: false, credentialsId: 'Sonar-token'
}
}
}
stage('Install Dependencies') {
steps {
sh "npm install"
}
}
stage('OWASP FS San') {
steps {
dependencyCheck additionalArguments: '--scan ./ --disableYarnAudit --disableNodeAudit', odcInstallation: 'DP-Check'
dependencyCheckPublisher pattern: '**/dependency-check-report.xml'
}
}
stage('Trivy FS Scan') {
steps {
sh "trivy fs . > trivyfs.txt"
}
}
stage("Docker Build & Push") {
steps {
script {
withDockerRegistry(credentialsId: 'docker', toolName: 'docker') {
sh "docker build -t reddit ."
sh "docker tag reddit tanishkamarrott/reddit:latest"
sh "docker push tanishkamarrott/reddit:latest"
}
}
}
}
stage("Trivy Image Scan") {
steps {
sh "trivy image tanishkamarrott/reddit:latest > trivy.txt"
}
}
stage('TruffleHog - Check secrets') {
steps {
sh 'docker run gesellix/trufflehog --json https://github.com/TanishkaMarrott/Reddit-Clone-App.git > trufflehog.json'
script {
def jsonReport = readFile('trufflehog.json')
def htmlReport = """
<html>
<head>
<title>Trufflehog Scan Report</title>
</head>
<body>
<h1>Trufflehog Scan Report</h1>
<pre>${jsonReport}</pre>
</body>
</html>
"""
writeFile file: 'scanresults/trufflehog-report.html', text: htmlReport
}
archiveArtifacts artifacts: 'scanresults/trufflehog-report.html', allowEmptyArchive: true
}
}
stage('Terraform - IaC Scan') {
when {
expression {
return sh(script: "find . -name '*.tf' | wc -l", returnStdout: true).trim() != "0"
}
}
steps {
script {
sh 'tfsec .'
}
}
}
}
post {
always {
archiveArtifacts artifacts: '**/*.tfsec', allowEmptyArchive: true
}
}
}