-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathJenkinsfile
81 lines (67 loc) · 2.22 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
pipeline {
agent any
environment {
NIGHTVISION_TOKEN = credentials('nightvision-token')
NIGHTVISION_TARGET = 'javaspringvulny-api'
NIGHTVISION_AUTH = 'javaspringvulny-api'
}
stages {
stage('Clone Code') {
steps {
checkout scm
}
}
stage('Install NightVision') {
steps {
script {
sh 'wget -c https://downloads.nightvision.net/binaries/latest/nightvision_latest_linux_amd64.tar.gz -O - | tar -xz'
sh 'python3 -m pip install --break-system-packages semgrep'
}
}
}
stage('Extract API Documentation from Code') {
steps {
script {
sh """
./nightvision swagger extract . -t "${env.NIGHTVISION_TARGET}" --lang spring || true
if [ ! -e openapi-spec.yml ]; then
cp backup-openapi-spec.yml openapi-spec.yml
fi
"""
}
}
}
stage('Start the App') {
steps {
script {
sh 'docker compose up -d; sleep 10'
}
}
}
stage('Scan the API') {
steps {
script {
sh """
./nightvision scan "${env.NIGHTVISION_TARGET}" --auth "${env.NIGHTVISION_AUTH}" > scan-results.txt
./nightvision export sarif -s \$(head -n 1 scan-results.txt) --swagger-file openapi-spec.yml > results.sarif
"""
}
}
}
stage('Upload SARIF file to Jenkins using Warnings Plugin') {
steps {
script {
// ensure the file exists and then publish it using the Warnings Next Generation Plugin
sh 'test -f results.sarif'
recordIssues tool: sarif(pattern: 'results.sarif')
}
}
}
}
post {
always {
// cleanup
sh 'docker compose down'
}
}
}