Debian Codegraph @

ansible_collections/netapp_eseries/santricity/vars/hubScanDocker.groovy

raw
1 def call(Map optional, String projectName, String projectVersion, String imageDirectory) {
2 optional.projectName = projectName
3 optional.projectVersion = projectVersion
4 optional.imageDirectory = imageDirectory
5 call(optional)
6 }
7
8
9 def call(Map optional) {
10
11 String projectVersion = optional.projectVersion
12 String projectName = optional.projectName
13 String imageDirectory = optional.imageDirectory
14 String url = "https://blackduck.eng.netapp.com"
15 String credId = 'hubProductionToken'
16
17 if((boolean) optional.staging){
18 url = "https://blackduck-staging.eng.netapp.com"
19 credId = 'hubStagingToken'
20 }
21
22 BLACKDUCK_SKIP_PHONE_HOME = true
23 withCredentials([string(credentialsId: credId, variable: 'TOKEN')]) {
24 String memory = optional.scannerMemoryMb ?: '8192'
25 String logLevel = optional.logLevel ?: 'INFO'
26 String coreCount = optional.coreCount ?: 1
27 String timeoutMinutes = optional.timeout ?: 60
28
29 sh''' wget -qN http://esgweb.eng.netapp.com/~lorenp/synopsys-detect-6.0.0-air-gap.zip -O /tmp/synopsys-detect.zip
30 unzip -u -d /tmp/tools /tmp/synopsys-detect.zip
31 rm -f /tmp/synopsys-detect.zip
32 '''
33
34 // Create the temporary directory for the scan logs
35 def scanTempDir = sh(returnStdout: true, script: "mktemp --directory \"/tmp/synopsys-detect-${projectName}-${projectVersion}-XXXXXXXXXX\"").trim()
36
37 echo "Initiating Hub Scanning Process on every image in ${imageDirectory}"
38 echo "Sending results to ${url}"
39 echo "Using a logLevel of ${logLevel}"
40 echo "Additional parameters: ${optional}"
41 echo "Running with a timeout value of ${timeoutMinutes} minutes"
42
43 // We need to locate all of the images to scan.
44 sh "find ${imageDirectory} -type f -iname '*.tar'> listFiles"
45 def files = readFile( "listFiles" ).split('\n');
46 try {
47 files.each {
48 def fileName = it.split('/')[-1];
49 timeout(time: "${timeoutMinutes}", unit: 'MINUTES') {
50 // Run a single scan for each image we find, using the filename as a scan identifier
51 sh """
52 java -Xms4096m -Xmx8192m -Xss1024m -jar /tmp/tools/synopsys-detect-6.0.0.jar \
53 --blackduck.url=${url} \
54 --detect.blackduck.signature.scanner.memory="${memory}" \
55 --detect.blackduck.signature.scanner.individual.file.matching="ALL" \
56 --blackduck.api.token=${TOKEN} \
57 --detect.docker.tar=${it} \
58 --detect.parallel.processors=${coreCount} \
59 --detect.code.location.name=${projectName}-${projectVersion}-${fileName} \
60 --detect.project.name=${projectName} \
61 --detect.project.version.name=${projectVersion} \
62 --detect.cleanup=false \
63 --blackduck.trust.cert=true \
64 --detect.output.path=${scanTempDir} \
65 --logging.level.com.synopsys.integration="${logLevel}"
66
67 """
68 }
69 }
70 } finally {
71 dir("${scanTempDir}") {
72 deleteDir()
73 }
74 }
75 }
76 }