Vasyl Saienko | 4e8ec64 | 2018-09-17 10:08:08 +0000 | [diff] [blame] | 1 | /** |
| 2 | * |
| 3 | * Run openscap xccdf evaluation on given nodes |
| 4 | * |
| 5 | * Expected parametes: |
Pavlo Shchelokovskyy | 319e00f | 2018-10-08 17:15:44 +0300 | [diff] [blame] | 6 | * OPENSCAP_TEST_TYPE Type of OpenSCAP evaluation to run, either 'xccdf' or 'oval' |
Vasyl Saienko | 4e8ec64 | 2018-09-17 10:08:08 +0000 | [diff] [blame] | 7 | * SALT_MASTER_URL Full Salt API address. |
| 8 | * SALT_MASTER_CREDENTIALS Credentials to the Salt API. |
| 9 | * |
Pavlo Shchelokovskyy | 319e00f | 2018-10-08 17:15:44 +0300 | [diff] [blame] | 10 | * XCCDF_BENCHMARKS_DIR Base directory for XCCDF benchmarks (default /usr/share/xccdf-benchmarks/mirantis/) |
| 11 | * or OVAL devinitions (default /usr/share/oval-definitions/mirantis/) |
Vasyl Saienko | 4e8ec64 | 2018-09-17 10:08:08 +0000 | [diff] [blame] | 12 | * XCCDF_BENCHMARKS List of pairs XCCDF benchmark filename and corresponding profile separated with ',' |
Pavlo Shchelokovskyy | 319e00f | 2018-10-08 17:15:44 +0300 | [diff] [blame] | 13 | * these pairs are separated with semicolon |
| 14 | * (e.g. manila/openstack_manila-xccdf.xml,profilename;horizon/openstack_horizon-xccdf.xml,profile). |
| 15 | * For OVAL definitions, paths to OVAL definition files separated by semicolon, profile is ignored. |
Vasyl Saienko | 4e8ec64 | 2018-09-17 10:08:08 +0000 | [diff] [blame] | 16 | * XCCDF_VERSION The XCCDF version (default 1.2) |
| 17 | * XCCDF_TAILORING_ID The tailoring id (default None) |
Ivan Udovichenko | 21892e6 | 2018-12-04 13:16:45 +0300 | [diff] [blame] | 18 | * XCCDF_CPE CPE dictionary or language for applicability checks (default None) |
Vasyl Saienko | 4e8ec64 | 2018-09-17 10:08:08 +0000 | [diff] [blame] | 19 | * |
| 20 | * TARGET_SERVERS The target Salt nodes (default *) |
| 21 | * |
| 22 | * ARTIFACTORY_URL The artifactory URL |
| 23 | * ARTIFACTORY_NAMESPACE The artifactory namespace (default 'mirantis/openscap') |
| 24 | * ARTIFACTORY_REPO The artifactory repo (default 'binary-dev-local') |
| 25 | * |
| 26 | * UPLOAD_TO_DASHBOARD Boolean. Upload results to the WORP or not |
| 27 | * DASHBOARD_API_URL The WORP api base url. Mandatory if UPLOAD_TO_DASHBOARD is true |
| 28 | */ |
| 29 | |
| 30 | |
| 31 | |
| 32 | /** |
| 33 | * Upload results to the `WORP` dashboard |
| 34 | * |
| 35 | * @param apiUrl The base dashboard api url |
| 36 | * @param cloudName The cloud name (mostly, the given node's domain name) |
| 37 | * @param nodeName The node name |
Pavlo Shchelokovskyy | f1b99b0 | 2018-10-02 20:31:17 +0300 | [diff] [blame] | 38 | * @param reportType Type of the report to create/use, either 'openscap' or 'cve' |
| 39 | * @param reportId Report Id to re-use, if empty report will be created |
| 40 | * @param results The scanning results as a json file content (string) |
| 41 | * @return reportId The Id of the report created if incoming reportId was empty, otherwise incoming reportId |
Vasyl Saienko | 4e8ec64 | 2018-09-17 10:08:08 +0000 | [diff] [blame] | 42 | */ |
Pavlo Shchelokovskyy | f1b99b0 | 2018-10-02 20:31:17 +0300 | [diff] [blame] | 43 | def uploadResultToDashboard(apiUrl, cloudName, nodeName, reportType, reportId, results) { |
Ivan Udovichenko | d1bd28c | 2018-10-02 12:41:04 +0300 | [diff] [blame] | 44 | def common = new com.mirantis.mk.Common() |
| 45 | def http = new com.mirantis.mk.Http() |
| 46 | |
Vasyl Saienko | 4e8ec64 | 2018-09-17 10:08:08 +0000 | [diff] [blame] | 47 | // Yes, we do not care of performance and will create at least 4 requests per each result |
| 48 | def requestData = [:] |
| 49 | |
| 50 | def cloudId |
| 51 | def nodeId |
| 52 | |
Pavlo Shchelokovskyy | f1b99b0 | 2018-10-02 20:31:17 +0300 | [diff] [blame] | 53 | def worpApi = [:] |
| 54 | worpApi["url"] = apiUrl |
| 55 | |
Vasyl Saienko | 4e8ec64 | 2018-09-17 10:08:08 +0000 | [diff] [blame] | 56 | // Let's take a look, may be our minion is already presented on the dashboard |
| 57 | // Get available environments |
Pavlo Shchelokovskyy | f1b99b0 | 2018-10-02 20:31:17 +0300 | [diff] [blame] | 58 | common.infoMsg("Making GET to ${worpApi.url}/environment/") |
| 59 | environments = http.restGet(worpApi, "/environment/") |
Vasyl Saienko | 4e8ec64 | 2018-09-17 10:08:08 +0000 | [diff] [blame] | 60 | for (environment in environments) { |
| 61 | if (environment['name'] == cloudName) { |
| 62 | cloudId = environment['uuid'] |
| 63 | break |
| 64 | } |
| 65 | } |
| 66 | // Cloud wasn't presented, let's create it |
| 67 | if (! cloudId ) { |
| 68 | // Create cloud |
Pavlo Shchelokovskyy | f1b99b0 | 2018-10-02 20:31:17 +0300 | [diff] [blame] | 69 | requestData = [:] |
| 70 | requestData['name'] = cloudName |
| 71 | common.infoMsg("Making POST to ${worpApi.url}/environment/ with ${requestData}") |
| 72 | cloudId = http.restPost(worpApi, "/environment/", requestData)['env']['uuid'] |
Vasyl Saienko | 4e8ec64 | 2018-09-17 10:08:08 +0000 | [diff] [blame] | 73 | |
| 74 | // And the node |
| 75 | // It was done here to reduce count of requests to the api. |
| 76 | // Because if there was not cloud presented on the dashboard, then the node was not presented as well. |
Pavlo Shchelokovskyy | f1b99b0 | 2018-10-02 20:31:17 +0300 | [diff] [blame] | 77 | requestData = [:] |
Vasyl Saienko | 4e8ec64 | 2018-09-17 10:08:08 +0000 | [diff] [blame] | 78 | requestData['nodes'] = [nodeName] |
Pavlo Shchelokovskyy | f1b99b0 | 2018-10-02 20:31:17 +0300 | [diff] [blame] | 79 | common.infoMsg("Making PUT to ${worpApi.url}/environment/${cloudId}/nodes/ with ${requestData}") |
| 80 | nodeId = http.restCall(worpApi, "/environment/${cloudId}/nodes/", "PUT", requestData)['uuid'] |
Vasyl Saienko | 4e8ec64 | 2018-09-17 10:08:08 +0000 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | if (! nodeId ) { |
| 84 | // Get available nodes in our environment |
Pavlo Shchelokovskyy | f1b99b0 | 2018-10-02 20:31:17 +0300 | [diff] [blame] | 85 | common.infoMsg("Making GET to ${worpApi.url}/environment/${cloudId}/nodes/") |
| 86 | nodes = http.restGet(worpApi, "/environment/${cloudId}/nodes/") |
Vasyl Saienko | 4e8ec64 | 2018-09-17 10:08:08 +0000 | [diff] [blame] | 87 | for (node in nodes) { |
| 88 | if (node['name'] == nodeName) { |
Pavlo Shchelokovskyy | f1b99b0 | 2018-10-02 20:31:17 +0300 | [diff] [blame] | 89 | nodeId = node['uuid'] |
Vasyl Saienko | 4e8ec64 | 2018-09-17 10:08:08 +0000 | [diff] [blame] | 90 | break |
| 91 | } |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | // Node wasn't presented, let's create it |
| 96 | if (! nodeId ) { |
| 97 | // Create node |
Pavlo Shchelokovskyy | f1b99b0 | 2018-10-02 20:31:17 +0300 | [diff] [blame] | 98 | requestData = [:] |
Vasyl Saienko | 4e8ec64 | 2018-09-17 10:08:08 +0000 | [diff] [blame] | 99 | requestData['nodes'] = [nodeName] |
Pavlo Shchelokovskyy | f1b99b0 | 2018-10-02 20:31:17 +0300 | [diff] [blame] | 100 | common.infoMsg("Making PUT to ${worpApi.url}/environment/${cloudId}/nodes/ with ${requestData}") |
| 101 | nodeId = http.restCall(worpApi, "/environment/${cloudId}/nodes/", "PUT", requestData)['uuid'] |
Vasyl Saienko | 4e8ec64 | 2018-09-17 10:08:08 +0000 | [diff] [blame] | 102 | } |
| 103 | |
Pavlo Shchelokovskyy | f1b99b0 | 2018-10-02 20:31:17 +0300 | [diff] [blame] | 104 | // Create report if needed |
| 105 | if (! reportId ) { |
| 106 | requestData = [:] |
| 107 | requestData['env_uuid'] = cloudId |
| 108 | common.infoMsg("Making POST to ${worpApi.url}/reports/${reportType}/ with ${requestData}") |
| 109 | reportId = http.restPost(worpApi, "/reports/${reportType}/", requestData)['report']['uuid'] |
| 110 | } |
Vasyl Saienko | 4e8ec64 | 2018-09-17 10:08:08 +0000 | [diff] [blame] | 111 | |
| 112 | // Upload results |
Pavlo Shchelokovskyy | f1b99b0 | 2018-10-02 20:31:17 +0300 | [diff] [blame] | 113 | // NOTE(pas-ha) results should already be a dict with 'results' key |
| 114 | requestData = common.parseJSON(results) |
Vasyl Saienko | 4e8ec64 | 2018-09-17 10:08:08 +0000 | [diff] [blame] | 115 | requestData['node_name'] = nodeName |
Pavlo Shchelokovskyy | f1b99b0 | 2018-10-02 20:31:17 +0300 | [diff] [blame] | 116 | common.infoMsg("First result in results to PUT is ${requestData['results'][0]}") |
| 117 | // NOTE(pas-ha) not logging whole results to be sent, is too large and just spams the logs |
| 118 | common.infoMsg("Making PUT to ${worpApi.url}/reports/${reportType}/${reportId}/ with node name ${requestData['node_name']} and results") |
| 119 | http.restCall(worpApi, "/reports/${reportType}/${reportId}/", "PUT", requestData) |
| 120 | return reportId |
Vasyl Saienko | 4e8ec64 | 2018-09-17 10:08:08 +0000 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | |
| 124 | node('python') { |
Vasyl Saienko | 4e8ec64 | 2018-09-17 10:08:08 +0000 | [diff] [blame] | 125 | def salt = new com.mirantis.mk.Salt() |
| 126 | def python = new com.mirantis.mk.Python() |
| 127 | def common = new com.mirantis.mk.Common() |
| 128 | def http = new com.mirantis.mk.Http() |
Dmitry Teselkin | 1691a2e | 2018-10-11 12:37:44 +0300 | [diff] [blame] | 129 | def validate = new com.mirantis.mcp.Validate() |
Vasyl Saienko | 4e8ec64 | 2018-09-17 10:08:08 +0000 | [diff] [blame] | 130 | |
Pavlo Shchelokovskyy | 319e00f | 2018-10-08 17:15:44 +0300 | [diff] [blame] | 131 | def pepperEnv = 'pepperEnv' |
| 132 | |
| 133 | def benchmarkType = OPENSCAP_TEST_TYPE ?: 'xccdf' |
| 134 | def reportType |
| 135 | def benchmarksDir |
| 136 | |
| 137 | switch (benchmarkType) { |
| 138 | case 'xccdf': |
| 139 | reportType = 'openscap'; |
| 140 | benchmarksDir = XCCDF_BENCHMARKS_DIR ?: '/usr/share/xccdf-benchmarks/mirantis/'; |
| 141 | break; |
| 142 | case 'oval': |
| 143 | reportType = 'cve'; |
| 144 | benchmarksDir = XCCDF_BENCHMARKS_DIR ?: '/usr/share/oval-definitions/mirantis/'; |
| 145 | break; |
| 146 | default: |
| 147 | throw new Exception('Unsupported value for OPENSCAP_TEST_TYPE, must be "oval" or "xccdf".') |
| 148 | } |
| 149 | // XCCDF related variables |
| 150 | def benchmarksAndProfilesArray = XCCDF_BENCHMARKS.tokenize(';') |
| 151 | def xccdfVersion = XCCDF_VERSION ?: '1.2' |
| 152 | def xccdfTailoringId = XCCDF_TAILORING_ID ?: 'None' |
Ivan Udovichenko | 21892e6 | 2018-12-04 13:16:45 +0300 | [diff] [blame] | 153 | def xccdfCPE = XCCDF_CPE ?: '' |
Pavlo Shchelokovskyy | 319e00f | 2018-10-08 17:15:44 +0300 | [diff] [blame] | 154 | def targetServers = TARGET_SERVERS ?: '*' |
| 155 | |
Vasyl Saienko | 4e8ec64 | 2018-09-17 10:08:08 +0000 | [diff] [blame] | 156 | // To have an ability to work in heavy concurrency conditions |
| 157 | def scanUUID = UUID.randomUUID().toString() |
| 158 | |
| 159 | def artifactsArchiveName = "openscap-${scanUUID}.zip" |
Ivan Udovichenko | d1bd28c | 2018-10-02 12:41:04 +0300 | [diff] [blame] | 160 | def resultsBaseDir = "/var/log/openscap/${scanUUID}" |
| 161 | def artifactsDir = "openscap" |
Vasyl Saienko | 4e8ec64 | 2018-09-17 10:08:08 +0000 | [diff] [blame] | 162 | |
| 163 | def liveMinions |
| 164 | |
Ivan Udovichenko | d1bd28c | 2018-10-02 12:41:04 +0300 | [diff] [blame] | 165 | |
Vasyl Saienko | 4e8ec64 | 2018-09-17 10:08:08 +0000 | [diff] [blame] | 166 | stage ('Setup virtualenv for Pepper') { |
| 167 | python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
| 168 | } |
| 169 | |
Pavlo Shchelokovskyy | 319e00f | 2018-10-08 17:15:44 +0300 | [diff] [blame] | 170 | stage ('Run openscap evaluation and attempt to upload the results to a dashboard') { |
Vasyl Saienko | 4e8ec64 | 2018-09-17 10:08:08 +0000 | [diff] [blame] | 171 | liveMinions = salt.getMinions(pepperEnv, targetServers) |
| 172 | |
| 173 | if (liveMinions.isEmpty()) { |
| 174 | throw new Exception('There are no alive minions') |
| 175 | } |
| 176 | |
| 177 | common.infoMsg("Scan UUID: ${scanUUID}") |
| 178 | |
Ivan Udovichenko | d1bd28c | 2018-10-02 12:41:04 +0300 | [diff] [blame] | 179 | // Clean all results before proceeding with results from every minion |
| 180 | dir(artifactsDir) { |
| 181 | deleteDir() |
| 182 | } |
| 183 | |
Pavlo Shchelokovskyy | f1b99b0 | 2018-10-02 20:31:17 +0300 | [diff] [blame] | 184 | def reportId |
Pavlo Shchelokovskyy | 011495f | 2018-10-10 13:03:57 +0300 | [diff] [blame] | 185 | def lastError |
Pavlo Shchelokovskyy | 82117e4 | 2018-10-03 19:48:56 +0300 | [diff] [blame] | 186 | // Iterate oscap evaluation over the benchmarks |
| 187 | for (benchmark in benchmarksAndProfilesArray) { |
Dmitry Teselkin | 1691a2e | 2018-10-11 12:37:44 +0300 | [diff] [blame] | 188 | def (benchmarkFilePath, profileName) = benchmark.tokenize(',').collect({it.trim()}) |
Vasyl Saienko | 4e8ec64 | 2018-09-17 10:08:08 +0000 | [diff] [blame] | 189 | |
Pavlo Shchelokovskyy | 82117e4 | 2018-10-03 19:48:56 +0300 | [diff] [blame] | 190 | // Remove extension from the benchmark name |
| 191 | def benchmarkPathWithoutExtension = benchmarkFilePath.replaceFirst('[.][^.]+$', '') |
Vasyl Saienko | 4e8ec64 | 2018-09-17 10:08:08 +0000 | [diff] [blame] | 192 | |
Pavlo Shchelokovskyy | 82117e4 | 2018-10-03 19:48:56 +0300 | [diff] [blame] | 193 | // Get benchmark name |
| 194 | def benchmarkName = benchmarkPathWithoutExtension.tokenize('/')[-1] |
Ivan Udovichenko | d1bd28c | 2018-10-02 12:41:04 +0300 | [diff] [blame] | 195 | |
Pavlo Shchelokovskyy | 82117e4 | 2018-10-03 19:48:56 +0300 | [diff] [blame] | 196 | // And build resultsDir based on this path |
Dmitry Teselkin | 1691a2e | 2018-10-11 12:37:44 +0300 | [diff] [blame] | 197 | def resultsDir = "${resultsBaseDir}/${benchmarkName}" |
| 198 | if (profileName) { |
| 199 | resultsDir = "${resultsDir}/${profileName}" |
| 200 | } |
Ivan Udovichenko | d1bd28c | 2018-10-02 12:41:04 +0300 | [diff] [blame] | 201 | |
Pavlo Shchelokovskyy | 82117e4 | 2018-10-03 19:48:56 +0300 | [diff] [blame] | 202 | def benchmarkFile = "${benchmarksDir}${benchmarkFilePath}" |
Vasyl Saienko | 4e8ec64 | 2018-09-17 10:08:08 +0000 | [diff] [blame] | 203 | |
Pavlo Shchelokovskyy | 82117e4 | 2018-10-03 19:48:56 +0300 | [diff] [blame] | 204 | // Evaluate the benchmark on all minions at once |
| 205 | salt.runSaltProcessStep(pepperEnv, targetServers, 'oscap.eval', [ |
Pavlo Shchelokovskyy | 319e00f | 2018-10-08 17:15:44 +0300 | [diff] [blame] | 206 | benchmarkType, benchmarkFile, "results_dir=${resultsDir}", |
Dmitry Teselkin | 1691a2e | 2018-10-11 12:37:44 +0300 | [diff] [blame] | 207 | "profile=${profileName}", "xccdf_version=${xccdfVersion}", |
Ivan Udovichenko | 21892e6 | 2018-12-04 13:16:45 +0300 | [diff] [blame] | 208 | "tailoring_id=${xccdfTailoringId}", "cpe=${xccdfCPE}" |
Pavlo Shchelokovskyy | 82117e4 | 2018-10-03 19:48:56 +0300 | [diff] [blame] | 209 | ]) |
Vasyl Saienko | 4e8ec64 | 2018-09-17 10:08:08 +0000 | [diff] [blame] | 210 | |
Dmitry Teselkin | 1691a2e | 2018-10-11 12:37:44 +0300 | [diff] [blame] | 211 | salt.cmdRun(pepperEnv, targetServers, "rm -f /tmp/${scanUUID}.tar.xz; tar -cJf /tmp/${scanUUID}.tar.xz -C ${resultsBaseDir} .") |
| 212 | |
| 213 | // fetch and store results one by one |
| 214 | for (minion in liveMinions) { |
Ivan Udovichenko | d1bd28c | 2018-10-02 12:41:04 +0300 | [diff] [blame] | 215 | def nodeShortName = minion.tokenize('.')[0] |
Pavlo Shchelokovskyy | 82117e4 | 2018-10-03 19:48:56 +0300 | [diff] [blame] | 216 | def localResultsDir = "${artifactsDir}/${scanUUID}/${nodeShortName}" |
Ivan Udovichenko | d1bd28c | 2018-10-02 12:41:04 +0300 | [diff] [blame] | 217 | |
Dmitry Teselkin | 1691a2e | 2018-10-11 12:37:44 +0300 | [diff] [blame] | 218 | fileContentBase64 = validate.getFileContentEncoded(pepperEnv, minion, "/tmp/${scanUUID}.tar.xz") |
| 219 | writeFile file: "${scanUUID}.base64", text: fileContentBase64 |
Ivan Udovichenko | d1bd28c | 2018-10-02 12:41:04 +0300 | [diff] [blame] | 220 | |
Pavlo Shchelokovskyy | 82117e4 | 2018-10-03 19:48:56 +0300 | [diff] [blame] | 221 | sh "mkdir -p ${localResultsDir}" |
Dmitry Teselkin | 1691a2e | 2018-10-11 12:37:44 +0300 | [diff] [blame] | 222 | sh "base64 -d ${scanUUID}.base64 | tar -xJ --strip-components 1 --directory ${localResultsDir}" |
| 223 | sh "rm -f ${scanUUID}.base64" |
| 224 | } |
Ivan Udovichenko | d1bd28c | 2018-10-02 12:41:04 +0300 | [diff] [blame] | 225 | |
Dmitry Teselkin | 1691a2e | 2018-10-11 12:37:44 +0300 | [diff] [blame] | 226 | // Remove archives which is not needed anymore |
| 227 | salt.runSaltProcessStep(pepperEnv, targetServers, 'file.remove', "/tmp/${scanUUID}.tar.xz") |
| 228 | |
| 229 | // publish results one by one |
| 230 | for (minion in liveMinions) { |
| 231 | def nodeShortName = minion.tokenize('.')[0] |
| 232 | def benchmarkResultsDir = "${artifactsDir}/${scanUUID}/${nodeShortName}/${benchmarkName}" |
| 233 | if (profileName) { |
| 234 | benchmarkResultsDir = "${benchmarkResultsDir}/${profileName}" |
| 235 | } |
Ivan Udovichenko | d1bd28c | 2018-10-02 12:41:04 +0300 | [diff] [blame] | 236 | |
Vasyl Saienko | 4e8ec64 | 2018-09-17 10:08:08 +0000 | [diff] [blame] | 237 | // Attempt to upload the scanning results to the dashboard |
| 238 | if (UPLOAD_TO_DASHBOARD.toBoolean()) { |
| 239 | if (common.validInputParam('DASHBOARD_API_URL')) { |
| 240 | def cloudName = salt.getGrain(pepperEnv, minion, 'domain')['return'][0].values()[0].values()[0] |
Pavlo Shchelokovskyy | 011495f | 2018-10-10 13:03:57 +0300 | [diff] [blame] | 241 | try { |
Dmitry Teselkin | 1691a2e | 2018-10-11 12:37:44 +0300 | [diff] [blame] | 242 | def nodeResults = readFile "${benchmarkResultsDir}/results.json" |
Pavlo Shchelokovskyy | 011495f | 2018-10-10 13:03:57 +0300 | [diff] [blame] | 243 | reportId = uploadResultToDashboard(DASHBOARD_API_URL, cloudName, minion, reportType, reportId, nodeResults) |
Dmitry Teselkin | 1691a2e | 2018-10-11 12:37:44 +0300 | [diff] [blame] | 244 | common.infoMsg("Report ID is ${reportId}.") |
Pavlo Shchelokovskyy | 011495f | 2018-10-10 13:03:57 +0300 | [diff] [blame] | 245 | } catch (Exception e) { |
| 246 | lastError = e |
| 247 | } |
Vasyl Saienko | 4e8ec64 | 2018-09-17 10:08:08 +0000 | [diff] [blame] | 248 | } else { |
| 249 | throw new Exception('Uploading to the dashboard is enabled but the DASHBOARD_API_URL was not set') |
| 250 | } |
| 251 | } |
| 252 | } |
| 253 | } |
Ivan Udovichenko | d1bd28c | 2018-10-02 12:41:04 +0300 | [diff] [blame] | 254 | |
| 255 | // Prepare archive |
| 256 | sh "tar -cJf ${artifactsDir}.tar.xz ${artifactsDir}" |
| 257 | |
| 258 | // Archive the build output artifacts |
| 259 | archiveArtifacts artifacts: "*.xz" |
Pavlo Shchelokovskyy | 011495f | 2018-10-10 13:03:57 +0300 | [diff] [blame] | 260 | if (lastError) { |
| 261 | common.infoMsg('Uploading some results to the dashboard report ${reportId} failed. Raising last error.') |
| 262 | throw lastError |
| 263 | } |
Vasyl Saienko | 4e8ec64 | 2018-09-17 10:08:08 +0000 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | /* // Will be implemented later |
| 267 | stage ('Attempt to upload results to an artifactory') { |
| 268 | if (common.validInputParam('ARTIFACTORY_URL')) { |
| 269 | for (minion in liveMinions) { |
| 270 | def destDir = "${artifactsDir}/${minion}" |
| 271 | def archiveName = "openscap-${scanUUID}.tar.gz" |
| 272 | def tempArchive = "/tmp/${archiveName}" |
| 273 | def destination = "${destDir}/${archiveName}" |
| 274 | |
| 275 | dir(destDir) { |
| 276 | // Archive scanning results on the remote target |
| 277 | salt.runSaltProcessStep(pepperEnv, minion, 'archive.tar', ['czf', tempArchive, resultsBaseDir]) |
| 278 | |
| 279 | // Get it content and save it |
| 280 | writeFile file: destination, text: salt.getFileContent(pepperEnv, minion, tempArchive) |
| 281 | |
| 282 | // Remove scanning results and the temp archive on the remote target |
| 283 | salt.runSaltProcessStep(pepperEnv, minion, 'file.remove', resultsBaseDir) |
| 284 | salt.runSaltProcessStep(pepperEnv, minion, 'file.remove', tempArchive) |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | def artifactory = new com.mirantis.mcp.MCPArtifactory() |
| 289 | def artifactoryName = 'mcp-ci' |
| 290 | def artifactoryRepo = ARTIFACTORY_REPO ?: 'binary-dev-local' |
| 291 | def artifactoryNamespace = ARTIFACTORY_NAMESPACE ?: 'mirantis/openscap' |
| 292 | def artifactoryServer = Artifactory.server(artifactoryName) |
| 293 | def publishInfo = true |
| 294 | def buildInfo = Artifactory.newBuildInfo() |
| 295 | def zipName = "${env.WORKSPACE}/openscap/${scanUUID}/results.zip" |
| 296 | |
| 297 | // Zip scan results |
| 298 | zip zipFile: zipName, archive: false, dir: artifactsDir |
| 299 | |
| 300 | // Mandatory and additional properties |
| 301 | def properties = artifactory.getBinaryBuildProperties([ |
| 302 | "scanUuid=${scanUUID}", |
| 303 | "project=openscap" |
| 304 | ]) |
| 305 | |
| 306 | // Build Artifactory spec object |
| 307 | def uploadSpec = """{ |
| 308 | "files": |
| 309 | [ |
| 310 | { |
| 311 | "pattern": "${zipName}", |
| 312 | "target": "${artifactoryRepo}/${artifactoryNamespace}/openscap", |
| 313 | "props": "${properties}" |
| 314 | } |
| 315 | ] |
| 316 | }""" |
| 317 | |
| 318 | // Upload artifacts to the given Artifactory |
| 319 | artifactory.uploadBinariesToArtifactory(artifactoryServer, buildInfo, uploadSpec, publishInfo) |
| 320 | |
| 321 | } else { |
| 322 | common.warningMsg('ARTIFACTORY_URL was not given, skip uploading to artifactory') |
| 323 | } |
| 324 | } |
| 325 | */ |
| 326 | |
| 327 | } |