66import groovy.json.JsonSlurperClassic
77
889+ 910gitCredID = ' marklogic-builder-github'
1011JIRA_ID = ' '
1112JIRA_ID_PATTERN = / (?i)(MLE)-\d {3,6}/
@@ -104,7 +105,7 @@ void resultNotification(message) {
104105 emailList = params. emailList
105106 }
106107 jira_link = " https://project.marklogic.com/jira/browse/${ JIRA_ID} "
107- email_body = " <b>Jenkins pipeline for</b> ${ env.JOB_NAME} <br><b>Build Number: </b>${ env.BUILD_NUMBER} <b ><br><br >Lint Output: <br></b>< pre><code>${ LINT_OUTPUT } </code></pre><br><br><b>Build URL: </b><br>${ env.BUILD_URL} "
108+ email_body = " <b>Jenkins pipeline for</b> ${ env.JOB_NAME} <br><b>Build Number: </b>${ env.BUILD_NUMBER} <br ><br><b >Lint Output: </b>< br><pre><code> ${ LINT_OUTPUT } </code></pre><br><br><b>Scan Output: </b><br>< pre><code>${ SCAN_OUTPUT } </code></pre><br><br><b>Build URL: </b><br>${ env.BUILD_URL} "
108109 jira_email_body = " ${ email_body} <br><br><b>Jira URL: </b><br>${ jira_link} "
109110
110111 if (JIRA_ID ) {
@@ -128,6 +129,18 @@ void lint() {
128129 '''
129130}
130131
132+ void imageScan () {
133+ sh " make image-scan saveOutput=true"
134+
135+ SCAN_OUTPUT = sh(returnStdout : true , script :' cat dep-image-scan.txt' )
136+ hasCriticalOrHigh = SCAN_OUTPUT . contains(" High" ) || SCAN_OUTPUT . contains(" Critical" )
137+ if (hasCriticalOrHigh) {
138+ mail charset : ' UTF-8' , mimeType : ' text/html' , to : " ${ emailSecList} " , body : " <br>Jenkins pipeline for ${ env.JOB_NAME} <br>Build Number: ${ env.BUILD_NUMBER} <br>Vulnerabilities: <pre><code>${ SCAN_OUTPUT} </code></pre>" , subject : " Critical or High Security Vulnerabilities Found: ${ env.JOB_NAME} #${ env.BUILD_NUMBER} "
139+ }
140+
141+ sh ''' rm -f dep-image-scan.txt'''
142+ }
143+
131144void publishTestResults () {
132145 junit allowEmptyResults :true , testResults : ' **/test/test_results/*.xml'
133146 archiveArtifacts artifacts : ' **/test/test_results/*.xml' , allowEmptyArchive : true
@@ -156,7 +169,7 @@ pipeline {
156169 skipStagesAfterUnstable()
157170 }
158171 triggers {
159- parameterizedCron( env. BRANCH_NAME == ' develop' ? ''' 00 04 * * *''' : ' ' )
172+ parameterizedCron( env. BRANCH_NAME == ' develop' ? ''' 00 04 * * * % IMAGE_SCAN=true ''' : ' ' )
160173 }
161174 environment {
162175 // timeStamp = sh(returnStdout: true, script: "date +%Y%m%d -d '-5 hours'").trim()
@@ -174,6 +187,7 @@ pipeline {
174187 choice(name : ' ML_VERSION' , choices : ' 11.2\n 12.0\n 10.0' , description : ' MarkLogic version. used to pick appropriate docker image' )
175188 booleanParam(name : ' KUBERNETES_TESTS' , defaultValue : true , description : ' Run kubernetes tests' )
176189 booleanParam(name : ' HC_TESTS' , defaultValue : false , description : ' Run Hub Central E2E UI tests (takes about 3 hours)' )
190+ booleanParam(name : ' IMAGE_SCAN' , defaultValue : false , description : ' Find and scan dependent Docker images for security vulnerabilities' )
177191 string(name : ' dockerReleaseVer' , defaultValue : ' 1.1.2' , description : ' Current Docker version. (e.g. 1.0.1)' , trim : true )
178192 choice(name : ' PREV_ML_VERSION' , choices : ' 10.0\n 9.0\n 11.2' , description : ' Previous MarkLogic version for MarkLogic upgrade tests' )
179193 string(name : ' prevDockerReleaseVer' , defaultValue : ' 1.1.2' , description : ' Previous Docker version for MarkLogic upgrade tests. (e.g. 1.0.1)' , trim : true )
@@ -193,6 +207,15 @@ pipeline {
193207 }
194208 }
195209
210+ stage(' Image-Scan' ) {
211+ when {
212+ expression { return params. IMAGE_SCAN }
213+ }
214+ steps {
215+ imageScan()
216+ }
217+ }
218+
196219 stage(' Kubernetes-Run-Tests' ) {
197220 when {
198221 expression { return params. KUBERNETES_TESTS }
0 commit comments