blob: 708a3a00b4eda8b3f3f1d6b181f8072a65c1c610 [file] [log] [blame]
Lionel Jouin4ca06662022-09-29 11:58:10 +02001
2node('nordix-nsm-build-ubuntu1804') {
3 build_number = env.BUILD_NUMBER
4 workspace = env.WORKSPACE
5 ws("${workspace}/${build_number}") {
6 def git_project = params.GIT_PROJECT
7 def current_branch = params.CURRENT_BRANCH
8 def default_branch = params.DEFAULT_BRANCH
9 def image_registry = params.IMAGE_REGISTRY
10 def version = params.IMAGE_VERSION
11 def email_recipients = EMAIL_RECIPIENTS
Lionel Jouin4b6b6f52022-10-14 16:22:23 +020012 def image_names = IMAGE_NAMES
Lionel Jouin4ca06662022-09-29 11:58:10 +020013
Lionel Jouin4b6b6f52022-10-14 16:22:23 +020014 def vulnerabilityBadge = addEmbeddableBadgeConfiguration(id: 'meridio-vulnerabilities', subject: 'vulnerabilities', color: 'peru', status: '?')
Lionel Jouin4ca06662022-09-29 11:58:10 +020015
16 timeout(30) {
17 stage('Clone/Checkout') {
18 git branch: default_branch, url: git_project
19 checkout([
20 $class: 'GitSCM',
21 branches: [[name: current_branch]],
22 extensions: [],
23 userRemoteConfigs: [[
24 refspec: '+refs/pull/*/head:refs/remotes/origin/pr/*',
25 url: git_project
26 ]]
27 ])
28 sh 'git show'
29 }
30 stage('Grype') {
Lionel Jouin4b6b6f52022-10-14 16:22:23 +020031 def command = "make grype VERSION=${version} REGISTRY=${image_registry} IMAGES='${image_names}'"
32 ExecSh(command).call()
Lionel Jouin4ca06662022-09-29 11:58:10 +020033 }
34 stage('Nancy') {
Lionel Jouin4b6b6f52022-10-14 16:22:23 +020035 def command = 'make nancy'
36 ExecSh(command).call()
Lionel Jouin4ca06662022-09-29 11:58:10 +020037 }
38 stage('Trivy') {
Lionel Jouin4b6b6f52022-10-14 16:22:23 +020039 def command = "make trivy VERSION=${version} REGISTRY=${image_registry} IMAGES='${image_names}'"
40 ExecSh(command).call()
Lionel Jouin4ca06662022-09-29 11:58:10 +020041 }
42 stage('Parse') {
Lionel Jouin4b6b6f52022-10-14 16:22:23 +020043 def command = './hack/parse_security_scan.sh'
44 ExecSh(command).call()
Lionel Jouin4ca06662022-09-29 11:58:10 +020045 }
46 stage('Report') {
47 archiveArtifacts artifacts: '_output/*', followSymlinks: false
48
Lionel Jouin4b6b6f52022-10-14 16:22:23 +020049 def number_of_vulnerabilities = sh(script: 'cat _output/list.txt | grep -v "^$" | awk \'{print $1}\' | sort | uniq | wc -l', returnStdout: true).trim()
50 def list_of_vulnerabilities = sh(script: 'cat _output/list.txt | grep -v "^$" | awk \'{print $1}\' | sort | uniq | sed \':a;N;$!ba;s/\\n/ ; /g\'', returnStdout: true).trim()
51 def number_of_high_severity_vulnerabilities = sh(script: 'cat _output/list.txt | grep -v "^$" | grep -i "high" | awk \'{print $1}\' | sort | uniq | wc -l', returnStdout: true).trim()
52 def list_of_high_severity_vulnerabilities = sh(script: 'cat _output/list.txt | grep -v "^$" | grep -i "high" | awk \'{print $1}\' | sort | uniq | sed \':a;N;$!ba;s/\\n/ ; /g\'', returnStdout: true).trim()
Lionel Jouin4ca06662022-09-29 11:58:10 +020053 def git_describe = sh(script: 'git describe --dirty --tags', returnStdout: true).trim()
54 def git_rev = sh(script: 'git rev-parse HEAD', returnStdout: true).trim()
55 def report = sh(script: 'cat _output/report.txt', returnStdout: true).trim()
56
Lionel Jouin4b6b6f52022-10-14 16:22:23 +020057 def subject = "Meridio - Security Scan - ${number_of_high_severity_vulnerabilities} high severity vulnerabilities detected"
Lionel Jouin4ca06662022-09-29 11:58:10 +020058 def body = """
59Run: ${RUN_DISPLAY_URL}
60git describe --dirty --tags: ${git_describe}
61git rev-parse HEAD: ${git_rev}
62Image registry: ${image_registry}
63Image Version: ${version}
64
Lionel Jouin4b6b6f52022-10-14 16:22:23 +020065Number of vulnerabilities: ${number_of_vulnerabilities}
66List of vulnerabilities: ${list_of_vulnerabilities}
Lionel Jouin4ca06662022-09-29 11:58:10 +020067
Lionel Jouin4b6b6f52022-10-14 16:22:23 +020068Number of vulnerabilities with high severity: ${number_of_high_severity_vulnerabilities}
69List of vulnerabilities with high severity: ${list_of_high_severity_vulnerabilities}
Lionel Jouin4ca06662022-09-29 11:58:10 +020070
71report:
72${report}
73"""
74 emailext body: "${body}", subject: "${subject}", to: "${email_recipients}"
75
Lionel Jouin4b6b6f52022-10-14 16:22:23 +020076 vulnerabilityBadge.setStatus("${number_of_vulnerabilities}")
Lionel Jouin4ca06662022-09-29 11:58:10 +020077 }
78 }
79 stage('Cleanup') {
80 Cleanup()
81 }
82 }
83}
84
85// Cleanup directory
86def Cleanup() {
87 cleanWs()
88}
Lionel Jouin4b6b6f52022-10-14 16:22:23 +020089
90// Execute command
91def ExecSh(command) {
92 return {
93 sh """
94 . \${HOME}/.profile
95 ${command}
96 """
97 }
98}