Merge "[DockerImageScanner] Log Jira activities"
diff --git a/src/com/mirantis/mk/DockerImageScanner.groovy b/src/com/mirantis/mk/DockerImageScanner.groovy
index 60a1332..b79ab85 100644
--- a/src/com/mirantis/mk/DockerImageScanner.groovy
+++ b/src/com/mirantis/mk/DockerImageScanner.groovy
@@ -214,8 +214,16 @@
return dict
}
+def logInfo(String infoText, String infoLogFile) {
+ if (infoLogFile) {
+ sh """#!/bin/bash -e
+ mkdir -p `dirname $infoLogFile`
+ echo "[`date +'%Y-%m-%d %H:%M:%S'`] ${errorText}" >> $infoLogFile
+ """
+ }
+}
-def reportJiraTickets(String reportFileContents, String jiraCredentialsID, String jiraUserID, String productName = '', String ignoreImageListFileContents = '[]', Integer retryTry = 0, String nvdApiUrl = '', jiraNamespace = 'PRODX', nvdNistGovCveUrl = 'https://nvd.nist.gov/vuln/detail/') {
+def reportJiraTickets(String reportFileContents, String jiraCredentialsID, String jiraUserID, String productName = '', String ignoreImageListFileContents = '[]', Integer retryTry = 0, String nvdApiUrl = '', String reportsDirLoc = '', jiraNamespace = 'PRODX', nvdNistGovCveUrl = 'https://nvd.nist.gov/vuln/detail/') {
def dict = [:]
def nvdDict = [:]
@@ -227,6 +235,10 @@
def search_api_url = "${cred.description}/rest/api/2/search"
+ def jiraLog = ''
+ if (reportsDirLoc) {
+ jiraLog = "${reportsDirLoc}/jira.log"
+ }
def jqlStartAt = 0
def jqlStep = 100
@@ -261,10 +273,10 @@
} else {
throw new Exception('Returned JSON from jql does not contain "issues" section')
}
- print 'Temporal debug information:'
- InputJSON['issues'].each {
- print it['key'] + ' -> ' + it['fields']['summary']
- }
+// print 'Temporal debug information:'
+// InputJSON['issues'].each {
+// print it['key'] + ' -> ' + it['fields']['summary']
+// }
InputJSON['issues'].each {
dict[it['key']] = [
@@ -322,6 +334,7 @@
// Ignore images listed
if ((image.key in ignoreImageList) || (image.key.replaceAll(/:.*$/, '') in ignoreImageList)) {
print "\n\nIgnoring ${image.key} as it has been found in Docker image ignore list\n"
+ logInfo("Ignoring ${image.key} as it has been found in Docker image ignore list", jiraLog)
return
}
@@ -376,7 +389,7 @@
if (filter_mke_severity) {
print "\n\nIgnoring ${image.key} as it does not have CVEs with CVSS base score >7\n"
- print jira_description
+ logInfo("Ignoring ${image.key} as it does not have CVEs with CVSS base score >7", jiraLog)
return
}
@@ -424,8 +437,10 @@
if ( post_comment_response['responseCode'] == 201 ) {
def issueCommentJSON = new JsonSlurper().parseText(post_comment_response["responseText"])
print "\n\nComment was posted to ${jira_key[0]} ${affectedVersion} for ${image_key} and ${image.key}"
+ logInfo("Comment was posted to ${jira_key[0]} ${affectedVersion} for ${image_key} and ${image.key}", jiraLog)
} else {
print "\nComment to ${jira_key[0]} Jira issue was not posted"
+ logInfo("Comment to ${jira_key[0]} Jira issue was not posted", jiraLog)
}
} else if (!jira_key[0]) {
def post_issue_response = callREST("${uri}/", auth, 'POST', post_issue_json)
@@ -433,11 +448,14 @@
def issueJSON = new JsonSlurper().parseText(post_issue_response["responseText"])
dict = updateDictionary(issueJSON['key'], dict, uri, auth, jiraUserID)
print "\n\nJira issue was created ${issueJSON['key']} ${affectedVersion} for ${image_key} and ${image.key}"
+ logInfo("Ignoring ${image.key} as it has been found in Docker image ignore list", jiraLog)
} else {
print "\n${image.key} CVE issues were not published\n"
+ logInfo("Ignoring ${image.key} as it has been found in Docker image ignore list", jiraLog)
}
} else {
print "\n\nNothing to process for ${image_key} and ${image.key}"
+ logInfo("Nothing to process for ${image_key} and ${image.key}", jiraLog)
}
}
}