Skip to content

MLE-19837 add blackduck scan #316

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import groovy.json.JsonSlurperClassic

emailList = '[email protected], [email protected], [email protected], [email protected], [email protected], [email protected]'
emailSecList = '[email protected], [email protected]'
emailSecList = '[email protected]'
gitCredID = 'marklogic-builder-github'
JIRA_ID = ''
JIRA_ID_PATTERN = /(?i)(MLE)-\d{3,6}/
Expand Down Expand Up @@ -103,7 +103,7 @@ def getReviewState() {
return reviewState
}

void resultNotification(message) {
void resultNotification(status) {
def author, authorEmail, emailList
if (env.CHANGE_AUTHOR) {
author = env.CHANGE_AUTHOR.toString().trim().toLowerCase()
Expand All @@ -117,11 +117,11 @@ void resultNotification(message) {
jira_email_body = "${email_body} <br><br><b>Jira URL: </b><br><a href='${jira_link}'>${jira_link}</a>"

if (JIRA_ID) {
def comment = [ body: "Jenkins pipeline build result: ${message}" ]
def comment = [ body: "Jenkins pipeline build result: ${status}" ]
jiraAddComment site: 'JIRA', idOrKey: JIRA_ID, failOnError: false, input: comment
mail charset: 'UTF-8', mimeType: 'text/html', to: "${emailList}", body: "${jira_email_body}", subject: "${message}: ${env.JOB_NAME} #${env.BUILD_NUMBER} - ${JIRA_ID}"
mail charset: 'UTF-8', mimeType: 'text/html', to: "${emailList}", body: "${jira_email_body}", subject: "🥷 ${status}: ${env.JOB_NAME} #${env.BUILD_NUMBER} - ${JIRA_ID}"
} else {
mail charset: 'UTF-8', mimeType: 'text/html', to: "${emailList}", body: "${email_body}", subject: "${message}: ${env.JOB_NAME} #${env.BUILD_NUMBER}"
mail charset: 'UTF-8', mimeType: 'text/html', to: "${emailList}", body: "${email_body}", subject: "🥷 ${status}: ${env.JOB_NAME} #${env.BUILD_NUMBER}"
}
}

Expand All @@ -147,6 +147,11 @@ void imageScan() {
}

sh '''rm -f dep-image-scan.txt'''

// trigger BlackDuck scan
def rawImageList = readFile(file: 'helm_image.list').trim()
def imageList = rawImageList.endsWith(',') ? rawImageList[0..-2] : rawImageList
build job: 'securityscans/Blackduck/KubeNinjas/kubernetes-helm', wait: false, parameters: [ string(name: 'branch', value: "${env.BRANCH_NAME}"), string(name: 'CONTAINER_IMAGES', value: "${imageList}") ]
}

void publishTestResults() {
Expand Down Expand Up @@ -261,13 +266,16 @@ pipeline {
sh "rm -rf $WORKSPACE/test/test_results/"
}
success {
resultNotification('BUILD SUCCESS ✅')
resultNotification('✅ Success')
}
failure {
resultNotification('BUILD ERROR ❌')
resultNotification('❌ Failure')
}
unstable {
resultNotification('BUILD UNSTABLE ❌')
resultNotification('⚠️ Unstable')
}
aborted {
resultNotification('🚫 Aborted')
}
}
}
2 changes: 2 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,10 @@ upgrade-test: prepare
.PHONY: image-scan
image-scan:

@rm -f helm_image.list dep-image-scan.txt
@echo "=====Scan dependent Docker images in charts/values.yaml" $(if $(saveOutput), | tee -a dep-image-scan.txt,)
@for depImage in $(shell grep -E "^\s*\bimage:\s+(.*)" charts/values.yaml | sed 's/image: //g' | sed 's/"//g'); do\
echo -n "$${depImage}," >> helm_image.list ; \
echo "= $${depImage}:" $(if $(saveOutput), | tee -a dep-image-scan.txt,) ; \
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock anchore/grype:latest --output json $${depImage} | jq -r '[(.matches[] | [.artifact.name, .artifact.version, .vulnerability.id, .vulnerability.severity])] | .[] | @tsv' | sort -k4 | column -t $(if $(saveOutput), | tee -a dep-image-scan.txt,);\
echo $(if $(saveOutput), | tee -a dep-image-scan.txt,) ;\
Expand Down