Skip to content

Commit 09530fa

Browse files
task #20 archive scan reports in Jenkins (updated Jenkinsfile).
@Khanbibi-devops @VladyslavZakharov @marinchik2205 @SvAdam25 @Eleonora2004 I configured Trivy to generate JSON vulnerability reports for each Docker image, stored them in a reports directory, and used Jenkins archiveArtifacts to archive the scan reports after every build. , before in Jenkinsfile we only were archiving artifacts. Now: After build: we can open Jenkins , click build number, scroll to Build Artifacts, and we will see: vote-scan-report.json result-scan-report.json worker-scan-report.json ✅ Task complete: Scan reports are archived.
1 parent 2f0a880 commit 09530fa

1 file changed

Lines changed: 38 additions & 14 deletions

File tree

Jenkinsfile

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ pipeline {
1414
steps {
1515
echo '🔨 Building Docker images...'
1616
sh '''
17-
docker build -t voting-app-vote ./vote
18-
docker build -t voting-app-result ./result
19-
docker build -t voting-app-worker ./worker
17+
docker build -t voting-app-vote:latest ./vote
18+
docker build -t voting-app-result:latest ./result
19+
docker build -t voting-app-worker:latest ./worker
2020
'''
2121
}
2222
}
@@ -35,15 +35,34 @@ pipeline {
3535
steps {
3636
echo '🔒 Running Trivy vulnerability scan...'
3737
sh '''
38-
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock \
39-
aquasec/trivy image --severity HIGH,CRITICAL --exit-code 1 \
40-
voting-app-vote:latest || echo "Vulnerabilities found in vote service"
41-
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock \
42-
aquasec/trivy image --severity HIGH,CRITICAL --exit-code 1 \
43-
voting-app-result:latest || echo "Vulnerabilities found in result service"
44-
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock \
45-
aquasec/trivy image --severity HIGH,CRITICAL --exit-code 1 \
46-
voting-app-worker:latest || echo "Vulnerabilities found in worker service"
38+
mkdir -p reports
39+
40+
docker run --rm \
41+
-v /var/run/docker.sock:/var/run/docker.sock \
42+
-v $(pwd)/reports:/reports \
43+
aquasec/trivy image \
44+
--severity HIGH,CRITICAL \
45+
--format json \
46+
-o /reports/vote-scan-report.json \
47+
voting-app-vote:latest || true
48+
49+
docker run --rm \
50+
-v /var/run/docker.sock:/var/run/docker.sock \
51+
-v $(pwd)/reports:/reports \
52+
aquasec/trivy image \
53+
--severity HIGH,CRITICAL \
54+
--format json \
55+
-o /reports/result-scan-report.json \
56+
voting-app-result:latest || true
57+
58+
docker run --rm \
59+
-v /var/run/docker.sock:/var/run/docker.sock \
60+
-v $(pwd)/reports:/reports \
61+
aquasec/trivy image \
62+
--severity HIGH,CRITICAL \
63+
--format json \
64+
-o /reports/worker-scan-report.json \
65+
voting-app-worker:latest || true
4766
'''
4867
}
4968
}
@@ -70,19 +89,24 @@ pipeline {
7089

7190
post {
7291
always {
73-
echo '📊 Archiving test reports and build artifacts...'
92+
echo '📊 Archiving scan reports and build artifacts...'
93+
94+
archiveArtifacts artifacts: 'reports/**/*.*', allowEmptyArchive: true, fingerprint: true
7495
archiveArtifacts artifacts: 'result/tests/test-report.txt', allowEmptyArchive: true
7596
archiveArtifacts artifacts: 'worker/bin/**/*.dll,worker/bin/**/*.exe', allowEmptyArchive: true
7697
archiveArtifacts artifacts: 'result/dist/**/*', allowEmptyArchive: true
7798
archiveArtifacts artifacts: 'vote/build/**/*', allowEmptyArchive: true
78-
99+
79100
junit testResults: 'result/tests/test-report.txt', allowEmptyResults: true
80101
}
102+
81103
success {
82104
echo '✅ Build successful!'
83105
}
106+
84107
failure {
85108
echo '❌ Build failed!'
86109
}
87110
}
88111
}
112+

0 commit comments

Comments
 (0)