-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
255 lines (224 loc) · 8.49 KB
/
Copy pathJenkinsfile
File metadata and controls
255 lines (224 loc) · 8.49 KB
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
@Library('report-generator') _
// General Configuration
def repoUrl = 'Application_URL'
// Configuration for the "SAST: Trufflehog" stage
def trufflehogRepoBranch = 'CloudGoat'
// Configuration for the "SCA: SonarQube" stage
def sonarProjectKey = 'CloudGoat'
def sonarExclusions = 'TFM/**/*'
pipeline {
agent {
kubernetes {
yaml '''
apiVersion: v1
kind: Pod
spec:
containers:
- name: python
image: python:3
command:
- cat
tty: true
- name: docker
image: docker:dind
securityContext:
privileged: true
tty: true
'''
}
}
stages {
stage('PREREQUIREMENTS') {
steps {
container('python') {
sh 'python3 --version || echo Python 3 is not installed'
echo 'Checking Pip...'
sh 'pip --version || echo Pip is not installed'
}
}
}
stage('[TEST]'){
steps{
echo '[TEST]'
}
}
stage("SCA: Safety") {
steps {
container('docker') {
sh '''
touch safety-results.json
chown 1000:1000 safety-results.json
'''
sh 'docker run -v "$(pwd)":/src --rm hysnsec/safety check -r requirements.txt --json | tee safety-results.json'
}
}
post {
always {
stash includes: 'safety-results.json', name: 'safety-results'
}
}
}
stage('SCA: SonarQube') {
steps {
script {
def scannerHome = tool 'SonarScanner1'
withSonarQubeEnv {
sh "${scannerHome}/bin/sonar-scanner -Dsonar.projectKey=${sonarProjectKey} -Dsonar.exclusions=${sonarExclusions}"
}
def sonarUrl = 'http://sonarqube-sonarqube.sonarqube.svc.cluster.local:9000'
withCredentials([string(credentialsId: '11a29cee-2600-4e76-8179-62a7a8cafffe', variable: 'SONAR_TOKEN')]) {
sh """
# Retrieve open issues
curl -u \$SONAR_TOKEN: -X GET "$sonarUrl/api/issues/search?componentKeys=${sonarProjectKey}&statuses=OPEN" > sonarqube_open_issues.json
# Retrieve opened security hotspots
curl -u \$SONAR_TOKEN: -X GET "$sonarUrl/api/hotspots/search?projectKey=${sonarProjectKey}&statuses=TO_REVIEW" > sonarqube_open_hotspots.json
"""
}
}
}
post {
always {
stash includes: 'sonarqube_open_issues.json', name: 'sonarqube_open_issues'
stash includes: 'sonarqube_open_hotspots.json', name: 'sonarqube_open_hotspots'
}
}
}
stage("SAST: Trufflehog") {
steps {
container('docker') {
catchError(buildResult: 'SUCCESS', stageResult: 'UNSTABLE') {
git branch: trufflehogRepoBranch,
url: repoUrl
sh '''
touch trufflehog-results.json
chown 1000:1000 trufflehog-results.json
'''
sh '''
echo '[' > trufflehog-results.json && \
docker run --user 1000:1000 -v "$(pwd)":/src --rm hysnsec/trufflehog file:///src --json | sed 's/}$/},/' | tee -a trufflehog-results.json && \
sed -i '$ s/},/}/' trufflehog-results.json && \
echo ']' >> trufflehog-results.json '''
}
}
}
post {
always {
stash includes: 'trufflehog-results.json', name: 'trufflehog-results'
}
}
}
stage("SAST: Bandit") {
steps {
container('docker') {
catchError(buildResult: 'SUCCESS', stageResult: 'UNSTABLE') {
sh 'docker run --user 1000:1000 -v "$(pwd)":/src --rm hysnsec/bandit -r /src -f json -o /src/bandit-results.json'
}
}
}
post {
always {
stash includes: 'bandit-results.json', name: 'bandit-results'
}
}
}
stage('[REPORTS CREATION]'){
steps{
echo '[REPORTS CREATION]'
}
}
stage('Setup Virtual Environment') {
steps {
container('python') {
sh 'python3 -m venv venv'
sh '. venv/bin/activate'
script {
def requirementsContent = libraryResource('requirements.txt')
writeFile file: 'requirements.txt', text: requirementsContent
sh 'pip install -r requirements.txt'
}
}
}
}
stage("Report Generation: SonarQube") {
steps {
container('python') {
script {
echo "Activating virtual environment:"
sh '. venv/bin/activate'
unstash 'sonarqube_open_issues'
unstash 'sonarqube_open_hotspots'
generateSonarqubeReport(issues_json: 'sonarqube_open_issues.json', hotspots_json: 'sonarqube_open_hotspots.json')
}
}
}
post {
always {
archiveArtifacts artifacts: 'sonarqube/sonarqube-report.html', fingerprint: true
}
}
}
stage("Report Generation: Safety") {
steps {
container('python') {
script {
echo "Activating virtual environment:"
sh '. venv/bin/activate'
unstash 'safety-results'
echo "Workspace directory is: ${env.WORKSPACE}"
generateSafetyReport(json: 'safety-results.json')
}
}
}
post {
always {
archiveArtifacts artifacts: 'safety/safety-report.html', fingerprint: true
}
}
}
stage("Report Generation: Trufflehog") {
steps {
container('python') {
script {
echo "Activating virtual environment:"
sh '. venv/bin/activate'
unstash 'trufflehog-results'
echo "Workspace directory is: ${env.WORKSPACE}"
generateTrufflehogReport(json: 'trufflehog-results.json')
}
}
}
post {
always {
archiveArtifacts artifacts: 'trufflehog/trufflehog-report.html', fingerprint: true
}
}
}
stage("Report Generation: Bandit") {
steps {
container('python') {
script {
echo "Activating virtual environment:"
sh '. venv/bin/activate'
unstash 'bandit-results'
generateBanditReport(json: 'bandit-results.json')
}
}
}
post {
always {
archiveArtifacts artifacts: 'bandit/bandit-report.html', fingerprint: true
}
}
}
stage('[Release]'){
steps{
echo '[Release]'
}
}
stage('Archive Artifacts') {
steps {
archiveArtifacts artifacts: '**/*.json', fingerprint: true
}
}
}
}